How to Display an alert in Record producer if form variable value not matched in table

vsharma
Tera Contributor

Hi All:

I have a Record producer (table - u_visitor with fields - Name/ mobile no/ checkin time/ checkout time/ state) where I need to check mobile number and if it matches in table then user state change to "checked out" else alert user to check mobile number and abort.

I tried but not able to get else condition work to alert user & abort process. Please suggest.

 

—— Record Producer Script section -------

var mno = producer.u_mobile_number;

var rec = new GlideRecord('u_visitor');

rec.addQuery('u_mobile_number', mno);

rec.query();

 

if (rec.next()) {

rec.u_state = 'checkedout';

rec.u_checkout_time = current.u_checkout_time;

rec.update();

current.setAbortAction(true);

Note: All RP form fields mapped to table fields.

 

Thanks

1 ACCEPTED SOLUTION

I just noted that this was a record producer. You could directly with the producer script. Can you please try this once after deactivating the client script and see if it works?

var mno = producer.u_mobile_number;
var rec = new GlideRecord('u_visitor');
rec.addQuery('u_mobile_number', mno);
rec.query();
if (rec.next()) {
rec.u_state = 'checkedout';
rec.u_checkout_time = current.u_checkout_time;
rec.update();
}else{
gs.addErrorMessage("Update Mobile number First");
current.setAbortAction(true);
//producer.redirect =""; 
} 

View solution in original post

28 REPLIES 28

It is not really submitted and your transaction is aborted, To what link are you redirecting the user?

Also please check if you see any errors in browser console log

Yes you are right that its not really submitted but not showing at the form. And, as far as redirection is concern I am able to redirect user via try it (Technical view) to record producer but not from service portal.

I tried your last shared method but not working. Please check if i missed anything.

producer.u_mobile_number = "";
current.setAbortAction(true);
gs.addErrorMessage("Record not found. Please check your mobile number");

-- for redirection--

var url = gs.action.getGlideURI();

if(url.indexOf("/vm/") > -1){

producer.redirect= "https://instance.service-now.com/vm?id=sc_cat_item&sys_id=c2ad000edb2a6b00594a54e84896190b&sysparm_category=ed4e7b3ddbe66b00594a54e848961958";

}else{

producer.redirect= "com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=c2ad000edb2a6b00594a54e84896190b";

}

 

And even not error on Browser console.

Is the issue on portal or platform view?

Change the redirection script to

var url = gs.action.getGlideURI();

if(url.indexOf("vm") > -1){

producer.redirect= "vm?id=sc_cat_item&sys_id=c2ad000edb2a6b00594a54e84896190b";

}else{

producer.redirect= "com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=c2ad000edb2a6b00594a54e84896190b";

}

Issue is on the service portal only. Script with redirection is ok on Platform view. Tried your revised script for redirection but not working on service portal.

I tested in my developer instance. Even without a redirect, it is working properly in portal. The error message is show and it stays on the form.

The redirect is only required on the platform view.  Not sure what issue is faced in your instance.