How to capture a field value in scratchpad within UI Action?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 07:09 AM
Hi Experts,
please tell me how I can 'catch" a field value in an UI Action within a scratchpad variable to be able to check for it within an Workflow that is triggered by the UI Action.
I was assuming something like "g_scratchpad.u_field = current.u_field;" would work ... but it doesn't.
Thank you.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 01:54 PM
g_scratchpad is used in client-side scripting.
http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#Example:_g_scratchpad
It is unclear how you intend to use this within a Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:09 PM
The use case is, that the UI action will change a field value that will trigger a workflow that includes an approval.
The UI action can run on 2 possible values of the field ... so in case of rejection, I would like to use the scratchpad to provide information about the field value of the moment, the UI action was triggerred (before the value changed) ... so that I can change back to that value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:10 PM
I guess it may be wrong.
scratchpad variable will bring the data from server to client.
http://wiki.servicenow.com/index.php?title=Using_the_Workflow_Scratchpad#gsc.tab=0.
Is your UI action contains client side and server side functionalities,
If then g_scratchpad_name = g_form.getValue('name');
var name1 = g_scratchpad_name;
server side function
executeFunction(name1);
send it as some parameter based function

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2017 02:18 PM
//UI Action
function clickedRRR(){
if(confirm('Sure?')){
gsftSubmit(null, g_form.getFormElement(), 'action_name');
}
return false;
}
// Server side code
if(typeof window == 'undefined')
myFunction();
function myFunction(){
// catch old u_field value in scratchpad
g_scratchpad_u_field = g_form.getValue('u_field'); // THIS IS WHAT YOU MEAN?
current.u_field= 'abc'; // Workflow waits for abc to start
current.update();
gs.addInfoMessage(gs.getMessage("Message"));
}