We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Automated Scripted Factors

hneeley
Tera Contributor

Is it possible to take yes/no variable fields or checkbox variable fields and turn them into numbers for scripted factors? If so, anyone have a sample script to try out? 

1 REPLY 1

Tanushree Maiti
Tera Patron

Hi @hneeley 

 

You can do it.

 

Sample code: 

 

var isApproved = current.variables.chkbox_variable.toString(); // Checkbox usually true/false
var chkAccess = current.variables.yesNo_variable.toString(); // Yes/No usually 'yes' or 'no'

//Convert to Numbers (1 for true/yes, 0 for false/no)
var checkboxValue = (isApproved === 'true' || isApproved === '1') ? 1 : 0;
var yesNoValue = (chkAccess === 'yes' || chkAccess === 'true') ? 1 : 0;

 

Using last 2 variable, you can calculate scripted factor or storing into Numeric field. 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti