How to put a condition based on Request item name in client script for sc_task table ?

Deepika61
Tera Contributor

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

5 REPLIES 5

Harshal Aditya
Mega Sage
Mega Sage

Hi @Deepika61 ,

 

I would suggest you to use UI policy for the same as its easy to maintain and you can easily define condition.

HarshalAditya_0-1677666411188.png

 

Please Mark My Response as Correct/Helpful based on Impact

Regards,
Harshal

 

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

@Deepika61 

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.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepika61 

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

AnkurBawiskar_0-1677666816728.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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