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

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriya 

you can use onChange client script + GlideAjax and get the message from that table

then use g_form.addInfoMessage() to show that

what did you start with and where are you stuck?

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

Hi @Ankur Bawiskar ,

 

Thanks for the response....Im new to script so i have not started yet.

It could be helpful if you provide the entire script.

 

Note: each users have different flash messages in their profile

Thanks in advance

@suuriya 

Below is the sample. I hope you will be able to enhance it further

create client callable script include

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; // use valid field name here
		}
		return '';
	},

	type: 'checkRecords'
});

onChange client script on User field on Call table

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

	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 ,

 

I used the above script it worked but it is displaying the sysid in annotation.... need the message value to be displayed.....can you let me know what change is needed here.

suuriya_0-1685089588709.png

And one thing i noticed if i select user with flash message the annotation displays if i change the user with no flashes still old annotation is showing in form is there any way we can work on this

 

Thanks