The CreatorCon Call for Content is officially open! Get started here.

How to access form variable in advanced script of View Rules

Rajesh M1
Giga Guru

Hello,

 

How to access form variables of a table in advanced script of View rules.

 

For example I have to access priority value of incident record to be fetched in the advanced script. 

current.priority is not returning any value.

Note: priority value is accessible through condition builder but my requirement is to access the value from script field.

find_real_file.png

Thanks in advance

Rajesh M.

6 REPLIES 6

bhtsai
Kilo Contributor

Since lists are in play, then there's no 'current' object available like there is a UI action or business rule. 

=> Totally a joke.

I can look at current object in condition, but not in advanced script?

Are lists not in play in simple mode?

midjoule
Kilo Sage

I agree that the design of these view rules is a bit confusing (condition builder vs script).

As a workaround, I've retrieved the sys_id from the URL and retrieved the corresponding record to check some additional fields. Here is my code:

(function overrideView(view, is_list) {	

	// doesn't apply the view to list views
	if (is_list)
		return ;

	//get URL details
	var url = gs.action.getGlideURI();
	
	//*** check if it is a MOU contract ("Partnership Agreement" contract model)	

	//retrieve the contract model that will be used to make sure this view rule only applies to MOU contracts
	var partnershipAgreementContractModel = gs.getProperty('mycompany.mou.contract_models');
	if (!partnershipAgreementContractModel)
		throw "[MOU Contract] view rule: Failed to get the system property [mycompany.mou.contract_models]" ;
		
	//retrieve the conctract and check the contract model against the system property
	var sysId = url.get('sys_id') ;	
	var contractGR = new GlideRecord('ast_contract');
	if (contractGR.get(sysId) && contractGR.contract_model == partnershipAgreementContractModel){		

		//check if the portal_id is provided in the URL or if the view is set to sp.
		if (typeof url.get('portal_id') == 'string' || url.get('view') == 'sp')
			answer = 'sp';  // set the service portal view
		else //not in the portal -> display the MOU view in the backend
			answer = 'MOU' ; //default MOU view

	}
})(view, is_list);

 Hope it can help someone.