Adding an if condition to a UI action

matthew_hughes
Kilo Sage

I've got a UI Action under the 'Related Links' called 'Generate/Continue BIA'. What I'm wanting to do is apply some logic so that it checks if the entries in the 'Divisional Application Owner' or 'Technical Application Owner' are active. If either one of the users are inactive and a user clicks on the 'Generate/Continue BIA' link, it should generate an error message 'The BIA cannot be generated/continued until both role holders are active' and keep them on the same page.

find_real_file.png

 

I was just wondering how I would get this applied to the UI action?

1 ACCEPTED SOLUTION

Hi,

update as this

function invokeAssessment() {

	if(g_form.getReference('u_business_owner').active.toString() == 'true' && g_form.getReference('u_custodian').active.toString() == 'true'){
		checkCurrentBia();
	}
	else{
		g_form.addErrorMessage('The BIA cannot be generated/continued until both role holders are active');
	}	
}

function checkCurrentBia(){

	var businessApp = g_form.getUniqueValue();
	//Access the glide ajax script include with the current sys id as a parameter
	var gaAssessment = new GlideAjax('LBGBiaUtils');
	gaAssessment.addParam('sysparm_name', 'currentAssessmentAjax');
	gaAssessment.addParam('sysparm_bus_app',businessApp);
	gaAssessment.getXML(generateAssessment);

	function generateAssessment(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		var data = answer.evalJSON(true);

		if (data.wipBia == 'false') {
			//generate pop up of UI page lbg_bia_dialog
			var displayValue = g_form.getDisplayValue();
			var biaDecisionPage = "lbg_bia_dialog";
			var dialogWindow = new GlideModal(biaDecisionPage, false, "modal-md");
			dialogWindow.setTitle(getMessage("Type of BIA"));
			dialogWindow.setPreference("displayValue", displayValue);
			//sysparm_id is the sys id of the current business app
			dialogWindow.setPreference("sysparm_id", g_form.getUniqueValue());
			dialogWindow.render();
			window.g_parentDialog = dialogWindow;
		} else {
			gsftSubmit(null, g_form.getFormElement(), 'action_bia');
		}
	}
}

if (typeof window == 'undefined')
	openCurrentBia();

function openCurrentBia() {
	var util = new LBGBiaUtils();
	var data = util.currentAssessment(current.getValue('sys_id'));
	var urlArray = [];
	urlArray.push(data.environmentUrl);
	urlArray.push(data.biaInstance);
	urlArray.push(data.biaMetricType);
	var instanceUrl = gs.getMessage('lbg.assessment.redirect.url' , urlArray);
	action.setRedirectURL(instanceUrl);
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

16 REPLIES 16

Mohith Devatte
Tera Sage
Tera Sage

Hello @matthew.hughes@lloydsbanking ,

You can write in ui action script like below hoping both the fields are referring to user table 

But make sure your client script is not "Client" checked.i.e client check box should be unchecked

if(current.divisional_application_owner_filed_name.active!=true || current.technical_application_owner_field_name.active!=true)

{

gs.addErrorMessage('The BIA cannot be generated/continued until both role holders are active');

current.setAbortAction(true);

}

please mark my answer correct if it helps you

Hi @Mohith Devatte  I would need to apply that within the script of the UI action?

yes @matthew.hughes@lloydsbanking you need to embed this in script

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

It means both users should be active to show the UI action on form

update UI action condition as this

current.u_divisional_application_owner.toString() == 'true' && current.u_technical_application_owner.toString() == 'true'

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader