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 add mappings to name value pairs field

Joe83
Kilo Contributor

Hi ServiceNow Community Developers,

I am using a name value par field for the first time and I am trying to populate the name and value using the script that ServiceNow provided as an example here

https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/field-administratio...

I am however running into an issue and I am not sure what is it that I am doing wrong. There are things that I am noticing that don’t look right to me with the provided script that I am using as my model here. The provided script has the initialize() function which to me says that we are going to create a record somewhere however I don’t see the insert() function in the provided script. I am not sure if I am missing something but would you please take a look ad advise.

Here is my script https://ven03962.service-now.com/nav_to.do?uri=sys_script_client.do?sys_id=5f7f41e21b0060102d0f99ba2... and it’s a very simple copy of the one the vendor provided above. It runs on loading of a change record.

Thanks,

John

1 ACCEPTED SOLUTION

So maybe if we take a step back and ask "what requirement are you solving for with this solution"? What is it you want or need to be able to do, onload of a change record, that you has you looking at this particular solution?

I can't say that I see anything actually wrong with your script, but as I mention, the values you are creating would only exist until the end of the onload scripts scope. You're not creating any lasting information using this method. To break it down: 

onload script starts:

var gr = new.... you are creating an instance of a class

gr.initialize()... you are calling a function of the class that the memory shell of a blank record on the table. A ghost if you will.

gr.u_xlr_variables.name1..... on thing to note here is that u_xlr_variables needs to exist on the table or this would do nothing - but here you are assigning a value to your ghost record. 

onload script ends: - since you are not writing to the database, all values in this script evaporate. 

So, in essence, your script is not producing a tangible result. 

Hope this helps!

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

 

 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

7 REPLIES 7

Hi Michael,

Thanks for your detailed response, greatly appreciate it. I will go through it in the morning and try to digest it properly, it's 1:33 AM here now and I need to go to bed I am so sleepy. 

In the meantime I have also attached a screenshot of my script. Please review and let me know if you can see straightaway what is it I am doing wrong.

Johannes

So maybe if we take a step back and ask "what requirement are you solving for with this solution"? What is it you want or need to be able to do, onload of a change record, that you has you looking at this particular solution?

I can't say that I see anything actually wrong with your script, but as I mention, the values you are creating would only exist until the end of the onload scripts scope. You're not creating any lasting information using this method. To break it down: 

onload script starts:

var gr = new.... you are creating an instance of a class

gr.initialize()... you are calling a function of the class that the memory shell of a blank record on the table. A ghost if you will.

gr.u_xlr_variables.name1..... on thing to note here is that u_xlr_variables needs to exist on the table or this would do nothing - but here you are assigning a value to your ghost record. 

onload script ends: - since you are not writing to the database, all values in this script evaporate. 

So, in essence, your script is not producing a tangible result. 

Hope this helps!

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

 

 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Joe83
Kilo Contributor

Hi Michael,

From your answer I got the idea on how I can get my issue resolved and I did. Basically u_xlr_variables is a field of type Name-Value Pairs defined on the change table. So all I had to to do in my onLoad script was to make sure that I look up the change record record using the sys_id and when the record is found I then updated the u_xlr_variables field. The Name-Value Pairs field basically hold a json object however i was hardcoding the json properties and the values when i got it to work. Now I am trying to assign them dynamically based on the field I am coming with when I call the script include that updates the u_xlr_variables and I am running into issues with that however in as far the question I was asking here that is now working as expected. 

Thanks for all your help.

John