Update a Reference Field on a Record, from Flow Designer Action, Script Step

Susan Sellmeye1
Tera Expert

How can I update a Reference Field on a Case, that points to the associated Incident Record? 

I need to be able to do this from a FD Action, Script Step

(see attachment)

 

Here are my inputs and script. The inputs are of type String

 

(function execute(inputs, outputs) {

 

// Set variable names for Step inputs
var grIMS = inputs.Record1;
var grCase = inputs.Record2;
var grINC = inputs.Record3;

 

// Queries for records created in Script Step 1
var rec1 = new GlideRecord('sn_customerservice_case');
rec1.addQuery('number',grCase);
rec1.query();

var rec2 = new GlideRecord('incident');
rec2.addQuery('number',grINC);
rec2.query();

 

 

// Get the SYSID of the Incident Record created in Script Step 1
// Assign new variable
var rec3 = new GlideRecord('incident');
rec3.addQuery('number',grINC);
rec3.query();

// Updates the Related Records on the Case created in Script Step 1, with the INC Record created in Script Step 1
while (rec1.next()) {
rec1.incident.number = rec4.getUniqueValue();
// rec1.updateWithReferences();
rec1.update();
}

____________________________________________

Here is what is happening:

If I use: rec1.update() > nothing is returned (the Incident reference field is blank on the Case Record)

If I use: rec1.updateWithReferences() > the Incident reference field gets populated on the Case Record, BUT it is a duplicate ticket with a different sysID

 

Any help here would be greatly appreciated!

Thank you

1 ACCEPTED SOLUTION

Thank you @ricker 

I needed to update the Case record with the related Incident Record (yes the incident reference field on the Case)

By utilizing the getUniqueValue() method in my original FD Action Script Step > I was able to obtain the sysid of the Case and the related Incident and output them as type: Document ID.  Then I was able to utilize the pre built actions Look Up Record and Update Record, which resolved my issue so I did not need to do any further scripting.

Thank you for your help!!!

 

View solution in original post

5 REPLIES 5

I did resolve it. Here was my solution:

I needed to update the Case record with the related Incident Record (yes the incident reference field on the Case)

By utilizing the getUniqueValue() method in my original FD Action Script Step > I was able to obtain the sysid of the Case and the related Incident and output them as type: Document ID.  Then I was able to utilize the pre built actions Look Up Record and Update Record, which resolved my issue so I did not need to do any further scripting.