How to fix the getxmlwait() not working in the service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 07:56 AM
Hi,
I have a requirement, where I have to create multiple request items under a single request using one catalog form having list collector variable.
For example If list collector have 3 values selected, than 3 records to be created with other variables cloned to all the records. List collector is referencing to client software table.
Working fine in the backend, not in the service portal. I got the error in the portal, because getXmlWait() not support.
Please anyone check this client script and script include. Give me your suggestions for how to fix it.
Client script:
function onSubmit() {
if(g_form.getValue("requested_for")==" ")
{
alert("Requested for should be filled");
g_form.setValue("requested_for","");
return false;
}
if(g_form.getValue("cb_new_hire")=="true")
{
var ga = new GlideAjax('AddItemsToCart');
ga.addParam('sysparm_name','createSoftwareItems');
ga.addParam('pls_chk_sa',g_form.getValue("pls_chk_sa"));
ga.addParam('software',g_form.getValue("software_search_sa2"));
ga.getXMLWait();
}else{
var soft = g_form.getValue("software_search_sa2").split(",");
var len = soft.length;
if(g_form.getValue("pls_chk_sa")=="true" && g_form.getValue("software_search_sa2")!="")
{
len++;
}
//alert("Software " + soft + len);
for (i = 1; i <len ; i++) {
//alert ("length " + soft[i]);
var ga1 = new GlideAjax('AddItemsToCart');
ga1.addParam('sysparm_name','addToCart');
ga1.addParam('software',soft[i]);
ga1.getXMLWait();
}
}
}
Script include:
var AddItemsToCart = Class.create();
AddItemsToCart.prototype = Object.extendsObject(AbstractAjaxProcessor, {
addToCart : function() {
// var software = this.getParameter('software');
var cat_item="40960a9213170600ff267d322244b0d1";
var quantity=1;
var cart = this.getCart();
var parent_item = this.nukeCart(cart,cat_item);
var cartID = cart.sys_id;
var gr = new GlideRecord('sc_cart_item');
if(parent_item!=null && gr.get(parent_item.sys_id))
{
}else{
gr.initialize();
}
gr.cart = cartID;
gr.cat_item = cat_item;
gr.quantity = quantity;
var newItem = gr.insert();
//gs.log("newItem :: " + gr.sys_id);
//this.addOptions(cartID,parent_item,newItem,software,cat_item);
},
addOptions : function(cartID,parent_item,newItem,iteration,cat_item) {
// Get the Cart Item
var kids = new GlideRecord('sc_cart_item');
//gs.log("kids :: " + kids.get(newItem));
if (kids.get(newItem)) {
// Look up the options for the item in the cart
var options = new GlideRecord('item_option_new');
options.addQuery('cat_item', cat_item);
options.query();
while(options.next())
{
gs.log("Software1 catitems" + cat_item);
var parOpt = new GlideRecord('sc_item_option');
parOpt.addQuery("item_option_new",options.sys_id);
parOpt.addQuery("cart_item",parent_item);
parOpt.query();
if(parOpt.next())
{
var gr = new GlideRecord('sc_item_option');
gr.initialize();
gr.item_option_new=options.sys_id;
if(options.name=="software_search_sa")
{
gr.value = software;
}else{
gr.value = parOpt.value;
}
gr.cart_item= kids.sys_id;
gs.log("Software1 Enter Kid" + cart_item);
gr.insert();
}
}
}
},
nukeCart : function(cart,cat_item) {
var id = cart.sys_id;
var kids = new GlideRecord('sc_cart_item');
kids.addQuery('cart', cart.sys_id);
kids.addQuery('cart_item', cat_item);
kids.query();
if(kids.next())
{
return kids;
}
return null;
},
CheckForDuplicate:function(){
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
var cartItem = new GlideRecord("sc_cart_item");
cartItem.addQuery("cart",cart.sys_id);
cartItem.addQuery("cat_item","40960a9213170600ff267d322244b0d1"); // check for softare request item
cartItem.query();
return cartItem.getRowCount();
}
return 0;
},
deleteSoftwareItem:function(){
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
var cartItem = new GlideRecord("sc_cart_item");
cartItem.addQuery("cart",cart.sys_id);
cartItem.addQuery("cat_item","40960a9213170600ff267d322244b0d1"); // check for softare request item
cartItem.query();
if(cartItem.next())
{
cartItem.deleteRecord();
}
}
},
createSoftwareItems: function(obj){
var currentRITM = this.CheckForDuplicate();
var softwares = this.getParameter('software').split(",");
var softLen=softwares.length;
var pls_chk_sa = this.getParameter('pls_chk_sa');
if(pls_chk_sa=="true" && this.getParameter('software')!="")
{
softLen++;
}
gs.log("software:ritm"+currentRITM);
gs.log("software:software"+softLen);
if(currentRITM > softLen)
{
for(ind=0;ind <(currentRITM-softLen);ind++)
{
this.deleteSoftwareItem();
}
}
if(currentRITM < softLen)
{
for(ind=0;ind <(softLen-currentRITM);ind++)
{
this.addToCart();
}
}
},
checkRepetition:function(obj){
var cartItems = new GlideRecord('sc_cart_item');
cartItems.addQuery("cart",obj.cart_item.cart.sys_id);
cartItems.query();
var itemOption = new GlideRecord('sc_item_option');
var qc;
if(cartItems.next())
{
qc=itemOption.addQuery('item_option_new', cartItems.item_option_new.sys_id);
}
while(cartItems.next())
{
if(cartItems.item_option_new!=null)
{
qc.addOrCondition('item_option_new', cartItems.item_option_new.sys_id);
}
}
itemOption.addQuery('cart_item', cartItems.cart_item.sys_id);
itemOption.query();
if(itemOption.getRowCount()>1)
{
return false;
}else{
return true;
}
/* }
}
*/
},
getCart:function() {
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
// we already have a cart all is well
}
else {
//gs.log("cart " + cart.user);
cart.initialize();
cart.user = userid;
cart.insert();
}
return cart;
},
doOrder:function() {
var req = new GlideappRequestNew();
req.copyCart();
},
type: 'AddItemsToCart'
});
Thanks,
Mukund
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 08:03 AM
Hello,
getXmlWait() or synchronous calls are not supported in service portal. You will need to move your validations to OnChange client scripts and call Ajax script with getXML() function. for eg Create an onchange client script on cb_new_hire when it changes to true and add your logic in here.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2018 09:37 AM
Hi Allikutty,
I tried this. Not working in the service portal. Please let us know any other way to achieve this.
Thanks,
Mukund
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2019 06:57 AM
You need to do GlideAjax and use getXML() with a function call and set the values in your function call. This isn't complete code, but should give you an idea of what I mean...
In the main code:
var ga = new GlideAjax('etc');
//Params etc...
getXML(newFunction);
function newFunction(response) {
var newVar = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('variable', newVar);
}