This function is used to insert a new record or update an existing record based on the matching field provided.
It will check if the matching field value exists in the system, if yes it will update the record otherwise it will create a new record
- Function: UpsertRecord (<Object Name>, <Matching Field>, <XML Data>, <use ExternalID>, <Asynchronous Update>)
- var ObjResult = UpsertRecord(<Object Name>, <Matching Field>, <XML Data>, <use ExternalID>, <Asynchronous Update>);
- var status = ObjResult.msgSuccess;
- var message = ObjResult.msgInfo;
- Use External Id: if the value is false, then you must send the GUID of the lookup fields in the XML data otherwise send the external Id value. Also if the parameter useExternalID is not existing in the function parameters, then it will considered as it is set to true.
- Asynchronous Update: This parameter is optional and has a default value of true. It triggers the calculation of sharing rules on the record asynchronously. When the API call is part of a series of dependent actions or when we need to immediately display the updated record to the user, it is advisable to set this parameter to false. The false value will indicate to Cirrus Shield that the sharing rules on the record should be calculated synchronously.
XML Data Format :
<Data> <Object Name> <Matching Field Name> Value </Matching Field Name> <Field Name> Value </Field Name> <Field Name> Value </Field Name> </Object Name> </Data>
- Usage: var objTask = GetDataByID(GetRecordGUID(),“Task”, “Id,Name,Start,End,Description,Location,Attendees,OwnerId”);
var offset = GetTimeZone(); var xmlStr = <Data>; xmlStr += <Task>; xmlStr += <Name>; xmlStr += objTask.Name; xmlStr += </Name>; xmlStr += <Start>; xmlStr += objTask.Start + offset; xmlStr += </Start>; xmlStr += <End>; xmlStr += objTask.End + offset; xmlStr += </End>; xmlStr += <Description>; xmlStr += Lunch Meeting; xmlStr += </Description>; xmlStr += <Location>; xmlStr += objTask.Location; xmlStr += </Location>; xmlStr += <Attendees>; xmlStr += objTask.Attendees; xmlStr += </Attendees>; xmlStr += <OwnerId>; xmlStr += objTask.OwnerId; xmlStr += </OwnerId>; xmlStr += </Task>; xmlStr += </Data>; var ObjResult = UpsertRecord("Task", "Name", xmlStr, false, true); var TaskGUID = ObjResult.msgSuccess; var message = ObjResult.msgInfo;
- Output:
- Success:
A success flag is returned with value = true.
The following message will be displayed “New record is saved successfully.” - Failure:
A success flag is returned with value = false.
An error message will be displayed.
- Success: