- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 09:14 PM - edited 07-16-2025 09:16 PM
I have a catalog item with a variable that I only want to display on the sctask form of a specific task after an approval request was rejected. (I tried to do this using a hidden variable but the catalog ui policy script couldn't access it because the variable is hidden?)
In the workflow create task activity, I've assigned the task sys_id to a workflow scratchpad variable. If I go to wf_context.LIST, I can see that the correct value is stored.
I created an on display business rule on the sc_task table to assign the workflow scratchpad value to a g_scratchpad value:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// Get the associated sc_req_item
var workflow = new Workflow();
var contexts = workflow.getRunningFlows(current.request_item);
if (contexts && contexts.length > 0) {
var scratchpad = contexts[0].scratchpad; // Get the first running workflow's scratchpad
if (scratchpad.equipmentOrderWithSurfaceReplacementTaskSysid) {
g_scratchpad.taskSysId = scratchpad.equipmentOrderWithSurfaceReplacementTaskSysid;
gs.info('Populated g_scratchpad.taskSysId: ' + g_scratchpad.taskSysId);
} }
})(current, previous);
Then I tried to use a catalog ui policy script to compare the current task sys_id to my scratchpad variable, but my g_scratchpad variable appears to be undefined according to alert(g_scratchpad...)
function onCondition() {
alert(g_scratchpad.taskSysId);
var currentTaskSysId = g_form.getUniqueValue(); // Get the sys_id of the current sc_task
var storedTaskSysId = g_scratchpad.taskSysId; // Get the stored sys_id from workflow scratchpad
if (currentTaskSysId && storedTaskSysId && currentTaskSysId === storedTaskSysId) {
g_form.setDisplay('suitable_surface_replacement_tablet_ordered',true);
g_form.setMandatory('suitable_surface_replacement_tablet_ordered', true);
}
}
Can someone tell me what I'm doing wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 09:50 PM
g_scratchpad variable from display business rule can't be accessed from catalog client script or catalog UI policy.
Use normal onLoad client script on sc_task and then update as this
function onLoad() {
var currentTaskSysId = g_form.getUniqueValue(); // Get the sys_id of the current sc_task
var storedTaskSysId = g_scratchpad.taskSysId; // Get the stored sys_id from workflow scratchpad
if (currentTaskSysId && storedTaskSysId && currentTaskSysId === storedTaskSysId) {
g_form.setDisplay('variables.suitable_surface_replacement_tablet_ordered', true);
g_form.setMandatory('variables.suitable_surface_replacement_tablet_ordered', true);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 10:08 PM
I already informed g_scratchpad is not accessible in catalog client scripts
So I shared the workaround above.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 10:26 PM
Thank you, @Ankur Bawiskar !
I apologize. I didn't even see your reply. I had the page still open and didn't refresh it before posting again.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 10:49 PM
No worries.
Glad to help.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader