- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2020 11:19 PM
we have record producer on custom table , after record created we have variables visible .
requriement is when those variables has to update table also has to update
i have made below code for single line text variables update in string field - before update businessrule which is working fine .
current.setValue('u_visualization' ,current.variables.visualization_owner.getDisplayValue());
current.setValue('u_pull_quote_or_data_highlight' ,current.variables.pull_quote);
But when i try to update few checkboxes variables trying to update in string field with comma separated value its not working
kindly correct code and please help
1) i tried in before business rule:
var checkboxes = ['ltc_financials', 'hospital_financials', 'hospital_chargemasters', 'hospital_community_benefit_plans', 'hospital_fair_pricing_policies', 'prescription_drug_rx_costs', 'healthcare_payments'];
var checkLable = ['Hospital Financials', 'LTC Financials', 'Hospital Chargemasters', 'Hospital Community Benefit Plans', 'Hospital Fair Pricing Policies', 'Prescription Drug (Rx) Costs', 'Healthcare Payments'];
for (var x = 0; x < checkboxes.length; x++) {
// if (checkboxes[x] == 'true') {
// var checkLable = current.variables.ltc_financials +',' + current.variables.hospital_financials +','+ current.variables.hospital_chargemasters +','+ current.variables.hospital_community_benefit_plans +','+ current.variables.hospital_fair_pricing_policies +','+ current.variables.prescription_drug_rx_costs +','+ current.variables.healthcare_payments;
current.setValue('u_cost_transparency', checkLable);
}
got error like undefined, undefined, undefined
2) tried below before update business rule:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var ltc = current.variables.ltc_financials;
var hosp = current.variables.hospital_financials;
var chrge = current.variables.hospital_chargemasters;
if (ltc == 'true') {
var ltc1 = 'Hospital Financials';
gs.log('ltc' + ltc1);
}
if (hosp == 'true') {
var hosp1 = 'LTC Financials';
gs.log('hosp' + hosp1);
}
if (chrge == 'true') {
var chrge1 = 'Hospital Chargemasters';
}
var abc = ltc1 + ',' + hosp1 + ',' + chrge1;
current.setValue('u_cost_transparency', abc);
})(current, previous);
3) and tried in onsubmit client script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var ltc = g_form.getValue('ltc_financials');
var hosp = g_form.getValue('hospital_financials');
var chrge = g_form.getValue('hospital_chargemasters');
if (ltc == 'true')
{
var ltc1= 'Hospital Financials';
}
if(hosp == 'true')
{
var hosp1 = 'LTC Financials';
}
if(chrge == 'true')
{
var chrge1 = 'Hospital Chargemasters';
}
var abc = ltc1+','+hosp1+','+chrge1;
g_form.setValue('u_cost_transparency',abc);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2020 11:40 PM
Hi,
So you want all the values from those checkboxes to be placed in u_cost_transparency
this should work fine in before update BR
See the changes
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var ltc = current.variables.ltc_financials;
var hosp = current.variables.hospital_financials;
var chrge = current.variables.hospital_chargemasters;
var abc = '';
if (ltc.toString() == 'true') {
abc = 'Hospital Financials';
gs.log('ltc' + ltc1);
}
if (hosp.toString() == 'true') {
abc = abc + ',' + 'LTC Financials';
gs.log('hosp' + hosp1);
}
if (chrge.toString() == 'true') {
abc = abc + ',' + 'Hospital Chargemasters';
}
current.setValue('u_cost_transparency', abc);
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2020 11:40 PM
Hi,
So you want all the values from those checkboxes to be placed in u_cost_transparency
this should work fine in before update BR
See the changes
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var ltc = current.variables.ltc_financials;
var hosp = current.variables.hospital_financials;
var chrge = current.variables.hospital_chargemasters;
var abc = '';
if (ltc.toString() == 'true') {
abc = 'Hospital Financials';
gs.log('ltc' + ltc1);
}
if (hosp.toString() == 'true') {
abc = abc + ',' + 'LTC Financials';
gs.log('hosp' + hosp1);
}
if (chrge.toString() == 'true') {
abc = abc + ',' + 'Hospital Chargemasters';
}
current.setValue('u_cost_transparency', abc);
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2020 08:02 AM
Could you please assist me for if these are list collector variable .
they are selected few choices in list collector , those has to save in comma separated value .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2020 08:12 AM
Hello Nitya,
If its a list collector variable, then do it in before BR like this
current.your_variable = current.variables.your_litstCollector.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2020 08:12 AM
Hi,
Is the list collector reference to some table?
if yes then you will directly get comma separated display value like this
var values = current.variables.listVariable.getDisplayValue();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader