Save-Buttons broken after filling LookupS through JScript
-
Friday, February 15, 2013 2:54 PM
I am currently developing a solution which contains a set of 5 custom-entities. A Lookup-Field for each of those Entities has been added to the default Contact-Form.
Within the OnChange-Event of the first entity a JScript is executed. This JScript fills the remaining 4 Lookup-Fields with the respective Entity (retrieved through multiple FetchXML-Requests) without any errors. However, if that JScript sets the Value of more than one Lookup at once, the default-Save-Ribbons stop working - no errors thrown or requests sent whatsoever - until the Values set through Code are removed from the related Lookup-Fields. If the JScripts only fills (any)one of those Lookups everything is working properly and the Entity can be saved as intended...
Any help/ideas would be greatly appreciated.
All Replies
-
Sunday, February 17, 2013 2:26 PM
Hi Hansli,
If you edit another field on the Contact Form and then try clicking 'Save', does the Save button work then? If so, then the problem will be how the fields are being populated automatically but not set as 'dirty' or 'changed' fields that need to be saved. When you set the value of the Lookup fields in JScript, make sure you are also using the SetSubmitMode method to tell CRM the value has changed and so should be saved.
If not and the Save button remains inactive even after other fields are updated - then the JavaScript must be interfering with the way the Ribbon is operating, which is rare but can sometimes happen. To see if this is the problem, you would need to post your script to let others take a look at where the script might be going wrong.
Hope that helps.
Kind Regards, Paul | http://crmconsultancy.wordpress.com
-
Sunday, February 17, 2013 8:00 PMAnswerer
As Paul mentioned the error could be analysed when you give us detailed information and perhaps you script. But, I have faced similar problem before. Some of your lookup fields maybe related to each other, and hence every value is not acceptable on it. Try to update fields (through javascript) on the logical order, which you want to update them! For example, if field A should be filled and then based on the result of the field A, field B choices reduces.
If the answer helped you, remember to mark it as answer.
-
Monday, February 18, 2013 5:03 PM
Thank you for your suggestions.
Unfortunately, the order in which the Lookup-Fields are populated is 'logically correct' and should not cause the issue either.
I had already thought of the missing OnChange-Action, but have not known of the SetSubmitMode-Statement. However, adding the respective code did not solve my problem.
//Code taken out of multiple Functions to hopefully help with the interpretation of the intended functionality function Snipplet () { var array = new Array(); array["bricks_stateprovince"] = null; //Retrieve all values of the respective custom-Entity var entityCollection = GetParentEntities(results, array); var state = null; //Fill the retrieved Values into variables if (entityCollection["bricks_stateprovince"]) { state = new Object(); state.id = entityCollection["bricks_stateprovince"].guid; state.name = entityCollection["bricks_stateprovince"].attributes['bricks_name'].value; state.entityType = entityCollection["bricks_stateprovince"].logicalName; } //Set the related CRM-Field's values to the filled variables var lookup = new Array(); if (state) { lookup[0] = state; Xrm.Page.getAttribute("bricks_address1_stateprovinceid").setValue(lookup); Xrm.Page.getAttribute("bricks_address1_stateprovinceid").fireOnChange(); Xrm.Page.getAttribute("bricks_address1_stateprovinceid").setSubmitMode('always'); } } //Recursive function to get all Entities function GetParentEntities(entity, entityCollection) { entityCollection[entity[0].logicalName] = entity[0]; if (entity[0].logicalName != 'bricks_country') { var parentEntity = GetParentEntity(entity); if (parentEntity) { entityCollection = GetParentEntities(parentEntity, entityCollection); } return entityCollection; } else { return entityCollection; } }In case the samle I attached does not provide sufficient information I will gladly upload the whole file (with about 1000 lines of code) - I have my concerns about readability though...
Kind regards and thanks in advance
- Edited by Hansli Hansen Tuesday, February 19, 2013 12:10 PM
-
Tuesday, February 19, 2013 2:29 PM
Can you please try this in your code:-
entityCollection["bricks_stateprovince"][0].guid;
Regards Faisal