
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 02:21 PM
I have a custom table that I'm trying to get linked so that users can create a Service Catalog Item and have it linked to the item within my custom table. I've created a ui action that opens a dialog window and displays all of the catalog items. When the users click okay after selecting the catalog item it should direct them to that catalog item to continue filling out the form. Can someone help me debug the issue of it not redirecting to the catalog item after it is selected?
I've created a UI Action called "Create Request"
function connectusCreateRequest(){
//Initialize and open the dialog
var dialog = new GlideDialogWindow("cu_get_connectus_catalog_item"); //Instantiate the dialog containing the UI Page 'cu_get_connectus_catalog_item_dialog'
dialog.setTitle("Choose a Catalog Item"); //Set the dialog title
dialog.render(); //Open the dialog
}
_________________________________________________________________________________________
I've created a UI Page called "cu_get_connectus_catalog_item"
Client Script within UI Page:
function validateCatItem() {
//This script is called when the user clicks "OK" in the dialog window
//Make sure there are comments to submit
var cat_item_id = gel("cat_item_id").value;
cat_item_id = trim(cat_item_id);
if (cat_item_id == "") {
//If comments are empty, alert the user and stop submission
alert("Please select a Catalog Item before submitting.");
return false;
}
//If there are comments, close the dialog window and submit them
GlideDialogWindow.get().destroy(); //Close the dialog window
g_form.setValue("catalog_item", cat_item_id); //Set the "Catalog Item" field with Catalog Item in the dialog
g_form.setValue('category', 'operational');
g_form.setValue('type', 'Service Request');
var page = g_form.getUniqueValue();
g_form.save();
// current.update();
var url = "catalog_home.do?sysparm_view=catalog_default&sysparm_processing_hint=setfield:request.parent=";
url += page;
action.setRedirectURL(url);
return true;
}
HTML within UI Page:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<!-- Set up form fields and labels -->
<table width="100%">
<tr id="description_row" valign="top">
<td colspan="2">
<!-- Short description value used as a label -->
Select a Catalog Item
</td>
</tr>
<tr>
<td>
<!-- Comments text field (Contains comments from originating record as a default) -->
<!-- <g:ui_multiline_input_field name="dialog_comments" id="dialog_comments" label="Additional comments"
value="${jvar_comments_text}" mandatory="true" /> -->
<g:ui_reference name="cat_item_id" id="cat_item_id" table="sc_cat_item" query="sc_catalogsLIKE71f876376fd242002ae02762be3ee477^sys_class_name!=sc_cat_item_content^ORsys_class_name=NULL^active=true"/>
<!-- completer="AJAXTableCompleter" columns="" -->
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr id="dialog_buttons">
<td colspan="2" align="right">
<!-- Add OK/Cancel buttons. Clicking OK calls the validateComments script -->
<g:dialog_buttons_ok_cancel ok="return validateCatItem()" ok_type="button" cancel_type="button" />
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
___________________________________________________________
I've created a Business Rule that runs after insert and update
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var number = current.number;
var reqFor = current.requested_for;
var location = current.requested_for.location;
var reqBy = current.requested_by;
var reqItem = current.catalog_item;
var shortDescription = current.shortdescription;
var businessCase = shortDescription + '\n' + current.business_case+ '\n\n' + 'Created from Demand: '+number;
var comments = "DEMAND_REF:"+current.sys_id+" "+businessCase;
var deadline = current.requested_delivery_date;
var desc = shortDescription + '\n' + current.description;
getCart();
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqItem + '&sysparm_user=' + reqFor + '&sysparm_requested_by=' + reqBy + '&sysparm_stnd_req_add_info=' + GlideStringUtil.urlEncode(desc) + '&sysparm_comments=' + comments;
action.setRedirectURL(url);
//Close out demand
var grCU = new GlideRecord('x_hemas_connectus2_x_hemas_connectus_connectus');
grCU.get(current.sys_id);
grCU.current_status = 'Complete';
grCU.update();
function getCart() {
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
// We already have a cart so override the requested for value and empty it
cart.requested_for = reqFor;
cart.special_instructions = comments;
cart.delivery_address = getDeliveryAddress();
cart.update();
var cartItems = new GlideRecord('sc_cart_item');
cartItems.addQuery('cart', cart.sys_id);
cartItems.deleteMultiple();
} else {
cart.initialize();
cart.user = userid;
cart.requested_for = reqFor;
cart.special_instructions = comments;
cart.delivery_address = getDeliveryAddress();
cart.insert();
}
return cart;
}
function getDeliveryAddress() {
var gr = new GlideRecord('cmn_location');
if (!gr.get(location))
return '';
var text = '';
if (!gr.street.nil())
text = gr.street + '\n';
if (!gr.city.nil() && !gr.state.nil() && !gr.zip.nil())
text += gr.city + ", " + gr.state + ", " + gr.zip;
return text;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 10:47 PM
Hi Edwin,
So it means the url you are forming is incorrect. here is the url you can try and test.
If I am correct you want to redirect user to the form which comes after you do Try it and user can populate values in the catalog variables.
Considering the page variable has the sys_id of the catalog item here is the URL
var url = '/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=' + page;
window.open(url,'_blank');
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 02:42 PM
Can you check if Client is set to true and Onclick on the UI Action is set to validateCatItem() .
- Client: True
- Onclick: validateCatItem()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 06:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 07:11 AM
I think the issue is within the UI Page. The client script within the UI page seems to work up until line 22 where it should redirect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 07:35 AM
Hi Edwin,
In the client script section of UI page action.setRedirectURL(url); will break since it is not allowed.
Instead use window.location or window.open();
Here is the updated script:
function validateCatItem() {
//This script is called when the user clicks "OK" in the dialog window
//Make sure there are comments to submit
var cat_item_id = gel("cat_item_id").value;
cat_item_id = trim(cat_item_id);
if (cat_item_id == "") {
//If comments are empty, alert the user and stop submission
alert("Please select a Catalog Item before submitting.");
return false;
}
//If there are comments, close the dialog window and submit them
GlideDialogWindow.get().destroy(); //Close the dialog window
g_form.setValue("catalog_item", cat_item_id); //Set the "Catalog Item" field with Catalog Item in the dialog
g_form.setValue('category', 'operational');
g_form.setValue('type', 'Service Request');
var page = g_form.getUniqueValue();
g_form.save();
// current.update();
var url = "catalog_home.do?sysparm_view=catalog_default&sysparm_processing_hint=setfield:request.parent=";
url += page;
window.open(url,'_blank');
return true;
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader