Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to set the value of a reference field?

jglez1
Mega Guru

So, I created a field called "Associated Incident" which is a plain-text field on a Case table, and  I also have a field called "Incident Short Description" which is of type Reference and refers to the Incident table.

 

What I want to happen is, an Agent enters an Incident number in the "Associated Incident" field, a script auto-populates the "Incident Short Description" reference field with the Short Description of the Incident the agent entered; and I have validation already checking if the Incident exists.

 

I was able to do this successfully with a plain-text field and simply using a GlideRecord if(gr.next()) statement

current.field_name = grIncident.field_name

But the problem is, say the Incident record is updated, using this method, the custom fields on my Case table won't reflect the updates from that Incident record because it was a one-time copy.

 

Now, I've made the "Incident Short Description" field of Reference type so the data is always up to date, but I can't seem to pull in the data into the field. What's a way this can be achieved?

 

Thank you.

1 ACCEPTED SOLUTION

Mehta
Kilo Sage

@jglez1 

 

I would suggest to make "associated incident" field as reference and make changes to script or business rule populate the "incident Short Description" field with short description from incident table. this field should be string. 

 

Once Done, You can create a business rule on incident table which will rule when short description gets updated. This business rule will glide record your custom case table against associated incident field and then update the short description. 

 

This approach is as per best practice and better architecture.

 

Please Mark helpful or correct Answer , If it solves your query.

View solution in original post

3 REPLIES 3

Mehta
Kilo Sage

@jglez1 

 

I would suggest to make "associated incident" field as reference and make changes to script or business rule populate the "incident Short Description" field with short description from incident table. this field should be string. 

 

Once Done, You can create a business rule on incident table which will rule when short description gets updated. This business rule will glide record your custom case table against associated incident field and then update the short description. 

 

This approach is as per best practice and better architecture.

 

Please Mark helpful or correct Answer , If it solves your query.

Thanks, Mehta!

This solution worked beautifully🙂 

ricker
Tera Guru

@jglez1,

Make an Incident reference field, the display value will be the INC number.  Add a dotwalked field to the form showing u_inc_ref.short_description....no coding needed and will always match if the short description is updated....using a business rule to populate the short description would not happen until AFTER the record is saved.