- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 10:10 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 11:47 AM
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!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 04:05 PM
Susan,
I think you're over complicating this.
What record are you trying to update? You mention a case record and an incident record and a reference field. I think you are trying to add an incident to the Incident reference field on a Case record? You should not need a script action step for this...should be a fairly simple Flow but need to understand what the requirement is.
rec2 and rec3 gliderecords are identical.
rec4 is not defined and getuniquevalue gets the sys_id
you also would not want to change the number field value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 11:47 AM
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!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 05:00 PM
That's awesome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 11:09 PM
Hi @Susan Sellmeye1 - Do you still have this issue open?