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.

Script Include Inserting Empty Record

stephaniet
Kilo Expert

Hi everyone,

This is my first "big" scripting project, so please bear with me.   I'd really appreciate your help.

I am trying to have the system automatically create a record in my new table called 'u_assignment_record' that includes who an incident was assigned to, who it is assigned to now, and who changed, every time someone updates the assigned to field on an incident.   I have it mostly working...except for the part where the record that the script include creates is blank.

Now, I tried using the OOB Metric for Assigned To duration, but this does not give me what we need in the format we need it.

Here is what I have so far.

CLIENT SCRIPT:

find_real_file.png

I want to pass the system ID's for all the values (the 'sysparm_who' value was a desperate attempt to figure out what I'm doing wrong...still didn't work), so that I can run reports on related fields for the values.   If I enable the commented out section in both the client script above and the script include below, I get an alert showing all the information I need (sys_id's for all values).

SCRIPT INCLUDE:

find_real_file.png

When I disable the alert parts above and change the value for an incident, I get a record in the u_assignment_record table BUT it's blank...

find_real_file.png

<xml>

<u_assignment_record>

<sys_created_by>stephanie.taveras</sys_created_by>

<sys_created_on>2016-11-07 19:13:29</sys_created_on>

<sys_id>d885d1800f87a200e867ee68b1050e06</sys_id>

<sys_mod_count>0</sys_mod_count>

<sys_updated_by>stephanie.taveras</sys_updated_by>

<sys_updated_on>2016-11-07 19:13:29</sys_updated_on>

<u_assigned_by/>

<u_assigned_from/>

<u_assigned_to/>

<u_number/>

</u_assignment_record>

</xml>

As you can see from the XML above, all 4 parameters that I try to pass are blank on my table.   I have tried setting these fields as Reference type, as String and as Translated Text.   Same thing happens for each type.   I did comment out the parameter and had it create a record with a static value (i.e '1', '2', '3', '4') and those values did pass into my table.

I would really appreciate anyone's help with this!

1 ACCEPTED SOLUTION

OK.. I messed around a bit with the setup.   You have to have the getXML() function, even if you do nothing with it:



find_real_file.png



find_real_file.png


find_real_file.png


View solution in original post

9 REPLIES 9

Mike Allen
Mega Sage

I would bet that maybe the var inc = new GlideRecord(incident) line is throwing things off.   It is not correct, not needed, and should be removed.



Try that and tell us what you get.


Also, is there a reason this is done Client Side?   If you do this, every time a user switches the assignment group in the form, it will log to the table, regardless of whether that was submitted or not.   So, if a user accidentally changes the assignment group, then changes it right back, that gets logged, though no change was actually done.   I think the better candidate for this is a before update business rule with a condition of assignment group changes.


Hi Mike, that was actually my original train of thought, and I tried to do it that way.   But for some reason I could not get the parameters I need to be sent from the business rule to the script include.   Could you give me an example of what it would need to look like?


OK.. I messed around a bit with the setup.   You have to have the getXML() function, even if you do nothing with it:



find_real_file.png



find_real_file.png


find_real_file.png