- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 07:47 PM
Hi,
I was hoping someone can help with a script that can be applied to the following scenario:
I have a variable set, that is included in 500 catalog items.
Some of these catalog items share an Automated workflow with the sys_id (XYZ)
In the variable set, I have a catalog UI policy to display or hide a checkbox variable.
The customer wants to have the checkbox displayed only if the Workflow is the Automated workflow with the sys_id (XYZ).
I do have have concept in my head, but cannot script it accurately.
Hopefully I have explained it clearly enough for anyone who can help.
Thank you in advance,
KS
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:26 PM
I think you can write onload catalog client script, Below is the sample script you can use:
function onLoad() {
// Get the current catalog item's workflow sys_id
var currentWorkflowSysID = g_form.getValue('sys_id_of_workflow_field'); // Replace 'sys_id_of_workflow_field' with the actual field name that holds the workflow sys_id
// Define the sys_id of the target workflow
var targetWorkflowSysID = 'XYZ'; // Replace 'XYZ' with the actual sys_id of the target workflow
// Get the checkbox variable field name
var checkboxFieldName = 'checkbox_variable_field'; // Replace 'checkbox_variable_field' with the actual field name of the checkbox variable
// Get the checkbox variable field element
var checkboxField = g_form.getControl(checkboxFieldName);
// Check if the current workflow is the target workflow
if (currentWorkflowSysID === targetWorkflowSysID) {
// Display the checkbox
checkboxField.style.display = '';
} else {
// Hide the checkbox
checkboxField.style.display = 'none';
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:26 PM
I think you can write onload catalog client script, Below is the sample script you can use:
function onLoad() {
// Get the current catalog item's workflow sys_id
var currentWorkflowSysID = g_form.getValue('sys_id_of_workflow_field'); // Replace 'sys_id_of_workflow_field' with the actual field name that holds the workflow sys_id
// Define the sys_id of the target workflow
var targetWorkflowSysID = 'XYZ'; // Replace 'XYZ' with the actual sys_id of the target workflow
// Get the checkbox variable field name
var checkboxFieldName = 'checkbox_variable_field'; // Replace 'checkbox_variable_field' with the actual field name of the checkbox variable
// Get the checkbox variable field element
var checkboxField = g_form.getControl(checkboxFieldName);
// Check if the current workflow is the target workflow
if (currentWorkflowSysID === targetWorkflowSysID) {
// Display the checkbox
checkboxField.style.display = '';
} else {
// Hide the checkbox
checkboxField.style.display = 'none';
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 07:31 AM
Thank you for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:54 PM
Hi @KS13
Let's give my approach a shot:
1. Create an AJAX Script Include that will query to the Catalog Item table to verify if the item is utilizing a specific workflow/flow.
Sample below.
var CLCatalogItemUtilAJAX = Class.create();
CLCatalogItemUtilAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isAutomatedWorkflow: function(){
var cat_item = this.getParameter('sysparm_cat_item');
var grItem = new GlideRecord('sc_cat_item');
grItem.addQuery('sys_id', cat_item);
grItem.addQuery('workflow', '<the_workflow_sys_id>'); //replace by flow_designer_flow if you're using flow designer. Avoid hard-coding by storing it in a property
grItem.query();
return grItem.hasNext();
},
type: 'CLCatalogItemUtilAJAX'
});
2. Create a new Client Script in the Variable Set to pass the Catalog Item sys_id to the isAutomatedWorkflow function and set display based on the response.
function onLoad() {
var cat_item = g_form.getUniqueValue(); //get catalog item sys_id in Portal
//you may need another Client Script that applies on Requested item and Catalog Task
//var cat_item = g_form.getValue('cat_item'); //get catalog item sys_id in ritm and sctask
var ga = new GlideAjax('CLCatalogItemUtilAJAX');
ga.addParam('sysparm_name', 'isAutomatedWorkflow');
ga.addParam('sysparm_cat_item', cat_item);
ga.getXMLAnswer(function(answer){
g_form.setDisplay('<your_field>', answer);
});
}
Cheers,
Tai Vu