What a setWorkflow(e) function does?

sreenivassinsta
Tera Contributor

i want to know the clear meaning of setworkflow() and scratchpad?

1 ACCEPTED SOLUTION

Deepak Kumar5
Kilo Sage

Setworkflow(false) is used to stop running any Business Rule written on that table for insert/update.


Ex- You have list of incident and you want to change State = Closed.


      in this case you run a script to closed all the incident but there are many Business Rules are written on incident table which run once incident get closed. like sending mail to requester,update any related records.


Since you don't want to sent notification so you can use setworkflow(false) to stop running any other script.



scratchpad


Uses to set a global variable which you can use in throughout the life of that record.


  Uses - Requirement of any field value in client side which are not present in form (in this case, you won't use g_form.getValue())


View solution in original post

4 REPLIES 4

HarshTimes
Tera Guru

HI Sreenu


setworkflow() takes the parameter true or false. Mostly it is user with parameter false. When you are running any script and you want that any other script should not trigger because of your script then we use this function.


Scratchpad helps to use the same field values between client side and server side


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sreenu,



In server side when you query some table and try to insert or update record and if you use setWorkflow(false); it will stop the triggering of business rule on that table.


scratchpad has 2 purpose


a) workflow scratchpad -> if you define workflow scratchpad variable in first activity you can use it as global variable in that workflow and any activity after the initial run script which set this scratchpad can use this variable


Activity 1 - Run Script


workflow.scratchpad.userId = 'abc';



Activity 2- Run Script


var workflowVariable = workflow.scratchpad.userId;



b) business rule scratchpad - this is use to send information from server side to client side.


declare g_scratchpad in display business rule and use it in onLoad, onChange and onSubmit client script



http://wiki.servicenow.com/index.php?title=Using_the_Workflow_Scratchpad


http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#Example:_g_scratchpad



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Deepak Kumar5
Kilo Sage

Setworkflow(false) is used to stop running any Business Rule written on that table for insert/update.


Ex- You have list of incident and you want to change State = Closed.


      in this case you run a script to closed all the incident but there are many Business Rules are written on incident table which run once incident get closed. like sending mail to requester,update any related records.


Since you don't want to sent notification so you can use setworkflow(false) to stop running any other script.



scratchpad


Uses to set a global variable which you can use in throughout the life of that record.


  Uses - Requirement of any field value in client side which are not present in form (in this case, you won't use g_form.getValue())


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sreenu,



Any update on this?


Can you mark answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


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