On change of user in field Need to display the pop-up message or annotation kind.

suuriya
Tera Contributor

Hi,

 

I have a requirement, In user form there is related list called flashes and it contains records in it. (only few users has flash records/message)

 

 

 

In call table, in the onbehalf field when the user is selected, who has flashes then the highlighted message should display as pop up or annotation kind of.

 

 

 

Example OLA SNOW has flash in his profile so on selecting this user profile, then the flash details need to display as pop up or annotation.

 

Please help me how we can achieve this....Provide the script as well.

 

Thanks in Advance.

 

1 ACCEPTED SOLUTION

@suuriya 

update as this

var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {

checkRecordPresent: function(){

var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('flashes table'); // use valid table name here
gr.addQuery('user', id); // use valid field name here
gr.query();
if(gr.next()){
return gr.flashesField.getDisplayValue(); // use valid field name here
}
return '';
},

type: 'checkRecords'
});

Client script:

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

	g_form.clearMessages();

	if(oldValue != newValue){
		var ga = new GlideAjax('checkRecords');
		ga.addParam('sysparm_name', "checkRecordPresent");
		ga.addParam('sysparm_userID', newValue); 
		ga.getXMLAnswer(function(answer){
			if(answer != ''){
				g_form.addInfoMessage(answer);
			}
		});
		//Type appropriate comment here, and begin script below
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

9 REPLIES 9

@suuriya 

update as this

var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {

checkRecordPresent: function(){

var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('flashes table'); // use valid table name here
gr.addQuery('user', id); // use valid field name here
gr.query();
if(gr.next()){
return gr.flashesField.getDisplayValue(); // use valid field name here
}
return '';
},

type: 'checkRecords'
});

Client script:

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

	g_form.clearMessages();

	if(oldValue != newValue){
		var ga = new GlideAjax('checkRecords');
		ga.addParam('sysparm_name', "checkRecordPresent");
		ga.addParam('sysparm_userID', newValue); 
		ga.getXMLAnswer(function(answer){
			if(answer != ''){
				g_form.addInfoMessage(answer);
			}
		});
		//Type appropriate comment here, and begin script below
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar,

 

In this case some user has more than 1 flash message in them but only the first message is getting displayed in case if they have 3 message all 3 needs to be displayed as annotations.

 

Can please help me for this modifications.

@suuriya 

update as this

var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	checkRecordPresent: function(){

		var arr = [];
		var id = this.getParameter('sysparm_userID');
		var gr = new GlideRecord('flashes table'); // use valid table name here
		gr.addQuery('user', id); // use valid field name here
		gr.query();
		while(gr.next()){
			arr.push(gr.flashesField.getDisplayValue()); // use valid field name here
		}
		return arr.toString();
	},

	type: 'checkRecords'
});
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Thanks for the quick response...Is there a way to get the annotation separate. Now I can see all annotation, but it is coming in single like annotation1,annotation2 

 

Is there way to get Annotation 1 in one blue box and annotation 2 in another.

@suuriya 

I didn't get

are you saying you want color for those messages in infoMessage?

if yes then it's possible. you can use html tags in it

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