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

I'm not sure why it appears for certain users.

Hi @Ankur Bawiskar  I've fixed it now. I removed toString() from my code.