Show field message dynamic for two catalog items

Sam198
Mega Guru

Hi all,

I have two catalog item that uses a variable set, the requirement on this variable set one variable to show two different message - I will need one Catalog item to show this message -   g_form.showFieldMsg('asset_in_stock',"... Asset in Stock Message 1",'info'); and the other catalog item to show separate message -   g_form.showFieldMsg('asset_in_stock',"... Asset in Stock Message 2",'info');

 

Is this possible?

Thanks in advance.

1 ACCEPTED SOLUTION

Hi Sam,

you need to use the syntax properly; updated script below: highlighted in bold you need to compare the variable each time

function onLoad() {
//Type appropriate comment here, and begin script below
var catalogItemSysId = g_form.getUniqueValue();
if(catalogItemSysId == 'sys_id' || catalogItemSysId == 'sys_id'|| catalogItemSysId == 'sys_id'|| catalogItemSysId == 'sys_id'){
g_form.showFieldMsg('asset_in_stock',"Asset in Stock Message 1",'info');

}
else if(catalogItemSysId == 'sys_id'){
g_form.showFieldMsg('asset_in_stock',"Asset not in Stock Message 2",'info');

}

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

7 REPLIES 7

Hi Sam,

you need to use the syntax properly; updated script below: highlighted in bold you need to compare the variable each time

function onLoad() {
//Type appropriate comment here, and begin script below
var catalogItemSysId = g_form.getUniqueValue();
if(catalogItemSysId == 'sys_id' || catalogItemSysId == 'sys_id'|| catalogItemSysId == 'sys_id'|| catalogItemSysId == 'sys_id'){
g_form.showFieldMsg('asset_in_stock',"Asset in Stock Message 1",'info');

}
else if(catalogItemSysId == 'sys_id'){
g_form.showFieldMsg('asset_in_stock',"Asset not in Stock Message 2",'info');

}

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Great Thats working - still learning scripts :))

Mark Roethof
Tera Patron
Tera Patron

Maybe already something like this?

	var catitemSysId = g_form.getUniqueValue();
	var messageStr = '';
	
	if(catitemSysId == 'some_sys_id_A') {
		messageStr = 'Message A';
	} else if(catitemSysId == 'some_sys_id_B') {
		messageStr = 'Message B';
	}
	
	g_form.showFieldMsg('asset_in_stock', messageStr);

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn