what is scratch pad?

sreenivassinsta
Tera Contributor

what is scratch pad, 

what is its use in business rules , client scripts, ui policies , workflows?

what is difference between scratchpad and ajax in clientscripts ?

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

 

Scratch pad is the temparory variable that can be used in workflows, BR and client scripts.

 

When we use the scratchpad in workflows we initiate it using below syntax:

workflow.scratchpad.abc = current.caller_id; you can anything instead of abc and assign any value to this scratchpad and use this scratchpad value in anyother activity in the same workflow as below :

gr.setValue('requested_for',workflow.scratchpad.abc);

 

Now when you use this scratchpad variable in BR then we initiate this object as below:

g_scratchpad.group = current.assignment_group; This should be used in Display BR and then we can use this scratchpad variable in client script as below:

g_form.setValue('fieldname',g_scratchpad.group);

 

Now coming to last question: Ajax is a proper may of calling a script include into client script and getting values from server which runs when we call it.

 

Display BR runs on load of a form, so this scratchpad value is available for you when the form loads. you can also do ajax call onload.


Thanks,

Ashutosh Munot

View solution in original post

6 REPLIES 6

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

 

Scratch pad is the temparory variable that can be used in workflows, BR and client scripts.

 

When we use the scratchpad in workflows we initiate it using below syntax:

workflow.scratchpad.abc = current.caller_id; you can anything instead of abc and assign any value to this scratchpad and use this scratchpad value in anyother activity in the same workflow as below :

gr.setValue('requested_for',workflow.scratchpad.abc);

 

Now when you use this scratchpad variable in BR then we initiate this object as below:

g_scratchpad.group = current.assignment_group; This should be used in Display BR and then we can use this scratchpad variable in client script as below:

g_form.setValue('fieldname',g_scratchpad.group);

 

Now coming to last question: Ajax is a proper may of calling a script include into client script and getting values from server which runs when we call it.

 

Display BR runs on load of a form, so this scratchpad value is available for you when the form loads. you can also do ajax call onload.


Thanks,

Ashutosh Munot

Akash4
Kilo Sage
Kilo Sage

Hi Sreenivas,

I would summarize the scratchpad as a global address where we can define our custom variables, so that we may use them at client side without giving a load to the server calls all the time.

g_scratchpad is used at Display BR which runs at on load and the variable defined in g_scratchpad is available at client side without any separate calls to server.

Secondly, workflow.scratchpad is used in the workflow editor because each activity in workflow is independent and they doesn't exist on a single table to reference one activity variables in another - say set Value (state) Activity variable is to be used at Approval Group. So, here we may use the workflow.scratchpad.myApprovalState = current.state

Hope you get a clear picture of not only what we use but also why we use the scratchpad variable.

Thanks, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

so scratchpad variable is used at Display BR only right?

not after, before, async business rules ?

Yeah only on Display BR.

Here is what a ServiceNow expert, chuck tomasi said - The g_scratchpad is an empty object you can use to push information (properties, objects, functions, custom variables etc.) from the server to the client. It is only available in display business rules and hence on client scripts

Thanks, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.