ShowField Message for List Collector

Community Alums
Not applicable

Hi,

ShowFieldMessage for List Collector script always showing the first message. It is not entering the second If block at all. Kindly help.

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var new_Variable = g_form.getDisplayValue('application').split(',');
    alert("new variable " + new_Variable);


    for (var i = 0; i < new_Variable.length; i++) {
      //  var new_Variable = g_form.getDisplayValue('application').split(',');

        alert("new variable for " + new_Variable[i]);
        if (new_Variable[i] == 'Chexar') {
            alert("if block Chexar");
            g_form.addInfoMessage("Used to assist customers with questions involving ATM Check Cashing.");
            // g_form.showFieldMsg('application', "Used to assist customers with questions involving ATM Check Cashing.", 'info', false);
        }


        if (new_Variable[i] == 'IVFR') {
            alert("if block ivfr");

            g_form.addInfoMessage("Grants override access to IVFR for Contact Center associates only.");
		
            // g_form.showFieldMsg("application", "Grants override access to IVFR for Contact Center associates only.", "info", false);
        }

        if (new_Variable[i] == 'TransPerfect') {
            alert("if block transperfect");

            g_form.addInfoMessage("Provide Interpreters to assist Contact Center agents.");
            //  g_form.showFieldMsg("application", "Provide Interpreters to assist Contact Center agents.", "info", false);
        }

        if (new_Variable[i] == 'SpeedPay') {
            alert("if block speedpay");

            g_form.addInfoMessage("Used to make payment from another financial institution.");
            // g_form.showFieldMsg("application", "Used to make payment from another financial institution.", "info", false);
        }

        if (new_Variable[i] == 'VerID') {
            alert("if block verid");

            g_form.addInfoMessage("Program that provide questions to be ask of customer to help verify identity.");
            //   g_form.showFieldMsg("application", "Program that provide questions to be ask of customer to help verify identity.", "info", false);
        }
		
    }
}

 

 

Picture.PNG

 

Regards

Suman P.

9 REPLIES 9

Maik Skoddow
Tera Patron
Tera Patron

Hi @Community Alums 

method getDisplayValue() for list collector fields doesn't work.

What you can do is using getValue()

Maik

Community Alums
Not applicable

Hi @Maik Skoddow ,

getValue is giving me sysID.

 

sysID.PNG

 

Regards

Suman P.

Hi @Community Alums 

yes, that's correct, as this is how a list collector is storing references internally. In your code, you just have to replace the display names of your variables and use the sys id values instead. At the end, this is the better approach because your code will not break anymore after changing the display values of your variables.

Maik

Sagar Pagar
Tera Patron

Hi @Community Alums,

 

Script looks good to me. Make sure that the display values are correct and exact matching with if conditions.

 

Try this updated scripts. Added toString() before splitting by comma.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	var new_Variable = g_form.getDisplayValue('application').toString().split(',');
	alert("new variable " + new_Variable);


	for (var i = 0; i < new_Variable.length; i++) {
		//  var new_Variable = g_form.getDisplayValue('application').split(',');

		alert("new variable for " + new_Variable[i]);
		if (new_Variable[i] == 'Chexar') {
			alert("if block Chexar");
			g_form.addInfoMessage("Used to assist customers with questions involving ATM Check Cashing.");
			// g_form.showFieldMsg('application', "Used to assist customers with questions involving ATM Check Cashing.", 'info', false);
		}


		if (new_Variable[i] == 'IVFR') {
			alert("if block ivfr");

			g_form.addInfoMessage("Grants override access to IVFR for Contact Center associates only.");

			// g_form.showFieldMsg("application", "Grants override access to IVFR for Contact Center associates only.", "info", false);
		}

		if (new_Variable[i] == 'TransPerfect') {
			alert("if block transperfect");

			g_form.addInfoMessage("Provide Interpreters to assist Contact Center agents.");
			//  g_form.showFieldMsg("application", "Provide Interpreters to assist Contact Center agents.", "info", false);
		}

		if (new_Variable[i] == 'SpeedPay') {
			alert("if block speedpay");

			g_form.addInfoMessage("Used to make payment from another financial institution.");
			// g_form.showFieldMsg("application", "Used to make payment from another financial institution.", "info", false);
		}

		if (new_Variable[i] == 'VerID') {
			alert("if block verid");

			g_form.addInfoMessage("Program that provide questions to be ask of customer to help verify identity.");
			//   g_form.showFieldMsg("application", "Program that provide questions to be ask of customer to help verify identity.", "info", false);
		}

	}
}

 

 If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow