Announcements
I need create a Contact record when this dont exits into a Dyn CRM 365. But the creation must be automatically. Let me show the situation and my code
This my code
Hi Shiongo,
If you fill in an un-exist record in a LookUp field, you will not be able to save the form.
So I recommend to trigger this JS function at "on change" action of the LookUp filed instead of "On Save".
According to your code, you just tested if the record existed. I suggest that you could refer to the solution:
1.If the record not exists, use WebApi to create a new record.
You could refer to the sample code bellow from SDK.
POST [Organization URI]/api/data/v9.0/contacts HTTP/1.1 Content-Type: application/json; charset=utf-8 OData-MaxVersion: 4.0 OData-Version: 4.0 Accept: application/json { "firstname": "Sample", "lastname": "Contact", "jobtitle": "jobtitle", "address1_line1": "address1_line1" }
2.After you create the record, you could catch the record by webapi and set the value to your lookup field.
You need GUID, Name, and Entity Name of the record which you want to set as a value to lookup field.
var Lookup= new Array(); Lookup[0] = new Object(); Lookup[0].id = “GUID”; // GUID of the record Lookup[0].name = “Name”; // Name of the record Lookup[0].entityType = “contact”; //Entity name of the record Xrm.Page.getAttribute(“FieldName”).setValue(Lookup); // set your record as value to filed.
Hope it helps.
Best Regards
Leo
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,802 Super User 2024 Season 2
Martin Dráb 229,133 Most Valuable Professional
nmaenpaa 101,154