Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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
Kilo 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: