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
Giga 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 mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: