How can a onSubmit catalog client script get data from one onChange catalog client script?

Student1
Tera Contributor

Hello,

I have an integration of SN with a third system.

I have a field: "Number" in a record producer. On this field I have set a on change catalog client script. So, every time that this value changes a rest api call is made to see if the number exists on the third system (I call a script include and the script include makes the call).

If so, another field "Description" is auto-populated with the data received from the third system. On the other hand, if it does not exist, an alert box pops up.

When the user submits the form, I want the number and the description to be inserted as new record on a custom table. For this, I can make a catalog client script on submit and call a script include to insert the new record.

However, for making this work, I need to take the description value that is fetched on the onchange client script.

Is there any way to make the onChange catalog client script to communicate with the onSubmit catalog client script?

In other words, my onSubmit catalog client script needs data from the onChange catalog client script.

Any ideas??

1 ACCEPTED SOLUTION

Hi,

it would take the latest value when your record producer script runs

So it would be 222 and BBB

var gr=new GlideRecord("u_custom_table");
gr.initialize();

gr.u_number = producer.number; // use valid number variable name here

gr.u_description = producer.description; // use valid description variable name here

gr.insert();

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

When your on change client scripts fetches the data, it populates it in the number and description fields, right?

If yes, then at the time of OnSubmit client script you can just read the value from number and description, as it was fetched by the onChange Client script.

You cannot pass the value from on change to on submit client script, but you can save it on any field on the form and read it on submit.

-Anurag

-Anurag

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

It's better you insert the record into custom table from the record producer script itself.

No need to use onSubmit with GlideAjax

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hey Ankur,

 

I need to write a script on the script field of my record producer??

For example, imagine the following scenario:

 

I write on number field "111" and the description is auto-populated from the third system as "AAA".

Then, before I submit it, I change my mind and I write on number field "222" and the description is auto-populated from the third system as "BBB".

 

Then I submit the form.

 

So, is the script on the record producer level going to take the last values of the field number and the field description (in this case: number=="222" and description=="BBB") ???

I will have something the following ????

var gr=new GlideRecord("u_custom_table");
gr.initialize();
gr.u_number=current.number; 
gr.u_description=current.description;
gr.insert();

 

Hi,

it would take the latest value when your record producer script runs

So it would be 222 and BBB

var gr=new GlideRecord("u_custom_table");
gr.initialize();

gr.u_number = producer.number; // use valid number variable name here

gr.u_description = producer.description; // use valid description variable name here

gr.insert();

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader