Catalog Client Script: Confirm before submit

palmen
Tera Guru

We've got a Catalog Client Script that works without any problem for one catalog item (Record Producer).

When I use the same script for another catalog item it's not working though, it's not showing the confirm popup.

Any idea why I get this behaviour?

This is the script we use

function onSubmit() {

  //Confirm popup to answer if an attachment has been attached.

  var answer = confirm("INSERT TEXT HERE ABOUT CONFIRM POPUP");

  if (answer == false) {

  return false;

  }

}

1 ACCEPTED SOLUTION

Thanks for the help b-rad it's working now.


No idea why the first sript didn't work, I just made an insert of the previous script we had for another catalog item.


After recreating and using g_form it works.



function onSubmit() {


  //Type appropriate comment here, and begin script below


  if (g_form.getValue('kategori') == '-112') {


  var answer = confirm("My Warning Text");


  if (answer == false) {


  return false;


  }


  }


}


View solution in original post

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I would think this should work in both cases. Do you have 2 different client scripts? Can you confirm that the type on this one is onsubmit?


palmen
Tera Guru

I recreated the Catalog Client Script (with exact same info) instead of using the previous one I inserted from another Catalog Client Script, and now it's working.



I want to add a condition from the Record Producer, how do I do this?


The popup should only appear if the Record producer variable "kategori" (a choice list) is "-112" (the value of the choice)



I tried with the following but it's not working


function onSubmit() {


  //Type appropriate comment here, and begin script below


  if (producer.kategori == '-112') {


  var answer = confirm("Min varning");


  if (answer == false) {


  return false;


  }


  }


}


Brad Tilton
ServiceNow Employee
ServiceNow Employee

producer.kategori would be server side and this CS is running client side so you need to use g_form. You should be able to replace it with g_form.getValue('kategori') == '-112'


Thanks for the help b-rad it's working now.


No idea why the first sript didn't work, I just made an insert of the previous script we had for another catalog item.


After recreating and using g_form it works.



function onSubmit() {


  //Type appropriate comment here, and begin script below


  if (g_form.getValue('kategori') == '-112') {


  var answer = confirm("My Warning Text");


  if (answer == false) {


  return false;


  }


  }


}