Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Change Request: Populate Category and Subcategory fields by Client Script

eltonasanto
Tera Contributor

Hi guys, how are you?!

 

There are 2 Changes: "Emergency" and "Normal"

 

I need only the NORMAL fields "Category" and "Subcategory" to be populated.

 

Both are in the Global scope, but I need it to be only for "Normal", so I would like to know if

it is possible to use the sysId of "Normal" (0f3e3f2283d02210062ecb65eeaad3c5)? (img1)

 

1) I created a template to populate some fields, but this is not a good option for the client (img2)

 

2) I tried to test using g_form_setValue:

 

function onLoad() {

//Type appropriate comment here, and begin script below

g_form.setValue('assigned_to',g_user.userID);

 

}

 

Could someone help me?

Thanks!

 

2 ACCEPTED SOLUTIONS

Vishal Jaswal
Giga Sage
Giga Sage

Hello @eltonasanto 

 

Whenever you select Normal then the Category and Subcategory fields to appear and whenever you select Emergency then these Categories and Subcategory fields remain hidden - To achieve this use UI policy where you don’t need to code.

 

I would encourage you to create UI policy for change_request table, apply the filter condition and then using it’s related list create UI policy actions.

 

Share your results here!

 

All the best and Happy Leanings!


Hope that helps!

View solution in original post

Shivalika
Mega Sage
Mega Sage

Hello @eltonasanto 

 

You want to populate category and subcategory only when change is normal and otherwise you want to hide it ? Is this the thing ? 

 

What is the issue you are facing exactly - not able to populate them correctly or not able to hide them correctly ? 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNe

EISQCY

 

View solution in original post

4 REPLIES 4

Vishal Jaswal
Giga Sage
Giga Sage

Hello @eltonasanto 

 

Whenever you select Normal then the Category and Subcategory fields to appear and whenever you select Emergency then these Categories and Subcategory fields remain hidden - To achieve this use UI policy where you don’t need to code.

 

I would encourage you to create UI policy for change_request table, apply the filter condition and then using it’s related list create UI policy actions.

 

Share your results here!

 

All the best and Happy Leanings!


Hope that helps!

Hi  @Vishal Jaswal, how are you?!

 

I would like to thank you for your tip (UI Policy instead of Client Script)

 

I have created it (example):

 

1) Filter: Model is Normal

 

 

2) function onCondition() {

g_form.setValue('category','hardware');

g_form.setValue('business_service', 'SAP Enterprise Services');

g_form.setValue('cmdb_ci','*ANNIE-IBM');

}

 

function onCondition() {

g_form.clearValue('category');

}

 

Thanks again!!! 😉

Shivalika
Mega Sage
Mega Sage

Hello @eltonasanto 

 

You want to populate category and subcategory only when change is normal and otherwise you want to hide it ? Is this the thing ? 

 

What is the issue you are facing exactly - not able to populate them correctly or not able to hide them correctly ? 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNe

EISQCY

 

Hi @Shivalika , how are you?!

 

A: You want to populate category and subcategory only when change is normal and otherwise you want to hide it ? Is this the thing ? 

 

Q: Yes! Only when Model is Normal.

 

I used UI Policy instead of Client Script and it is working.

 

I would like to thank you for your attention and support.

 

Best regards 😉