How to put a condition based on Request item name in client script for sc_task table ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 01:56 AM
Hi All,
Actually i have a requirement that i need to do make some fields mandatory and read only on the catalog task form based on one field choice , so i need to do this only one particular catalog item only, so for that in client script i need to put a condition like if catalog item is this, then only those fields mandatory or read only
Please help me to achieve this
Thanks
Deepika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 02:28 AM
Hi @Deepika61 ,
I would suggest you to use UI policy for the same as its easy to maintain and you can easily define condition.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 02:43 AM
Hi Harshal,
Thanks for the response
Actually my requirement was need achieve this through client script, so can you please tell me how to achieve this through client script?
Thanks
Deepika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 02:49 AM
using client script you can do this
1) onLoad client script on sc_task table
function onLoad(){
// Add your code here
var ritm = g_form.getReference('request_item', callBackMethod);
}
function callBackMethod(ritm){
if(ritm.cat_item == 'catItemSysId'){
// add your code here to make fields on sc_task form as mandatory or read-only
}
}
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
03-01-2023 02:34 AM
2 ways
1) you can use display business rule + onLoad client script on sc_task
If you require complex scripting logic for mandatory or read-only, I would suggest to use this
Display BR:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.catItemName = current.request_item.cat_item.name;
})(current, previous);
onLoad client script
function onLoad(){
// Add your code here
if(g_scratchpad.catItemName.toString() == 'Your Catalog Item Name Here'){
// add your code here to make fields on sc_task form as mandatory or read-only
}
}
OR
2) you can also create UI policy on sc_task and add that in condition field by dot walking Request Item field
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