Comments on: Mandatory Fields on Service Catalog Checkout Form https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/ ServiceNow Consulting Scripting Administration Development Tue, 28 May 2024 21:37:08 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Mike Tadder https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6656 Thu, 04 Aug 2016 12:27:12 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6656 Mark

I using FUJI and have read through all the postings. While Junior’s post was very helpful it appears to be missing something. I can get the checkMandatorySubmit to fire and receive the message “‘The following mandatory fields are not filled in: ” .. but the request is still being submitted.

Any solutions for this

]]>
By: ND https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6655 Mon, 04 Jul 2016 17:03:50 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6655 In reply to Junior.

Junior,

Thanks for the info you’ve posted. However, there is still some piece missing in your post. You did not mention which part of the sc_cart_view_buttons macro has to be edited and how the UI script can be called from it. I’m also working over Fuji version and finding it difficult to edit the xml.

Thanks!

]]>
By: Mike Tadder https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6654 Mon, 06 Jun 2016 18:40:37 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6654 In reply to Junior.

Junior

I found our reply to “Mandatory Fields on Service Catalog Checkout Form” about getting this to work in FUJI. I would like to use it but you seemed to have omitted something I need. You stated

” So, open this macro, find the line for the checkout button:

Change it to this:

Notice the change in the onClick property. We are calling a function, and if that function returns true, then we perform the checkout method.”

Can you please provide the rest of the what “Change it to this:” actually is?

]]>
By: Mike T https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6653 Fri, 22 Apr 2016 21:02:02 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6653 In reply to Junior.

Junior

I found our reply to “Mandatory Fields on Service Catalog Checkout Form” about getting this to work in FUJI. I would like to use it but you seemed to have omitted something I need. You stated

” So, open this macro, find the line for the checkout button:

Change it to this:

Notice the change in the onClick property. We are calling a function, and if that function returns true, then we perform the checkout method.”

Can you please provide the rest of the what “Change it to this:” actually is?

]]>
By: Junior https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6652 Fri, 25 Sep 2015 06:07:30 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6652 Okay, so I was half-way asleep whenever I posted my above post. I added a LOT more in there than just making it mandatory. To make it mandatory, all you need is to update the UI Macro, create the UI Script. That’s it. The rest is for copying fields to the cart then the request in the event you add additional fields. I couldn’t figure out how to edit my old post, so if someone can enlighten me on how to edit my own post, that would be awesome :)

]]>
By: Junior https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6651 Fri, 25 Sep 2015 04:27:22 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6651 Okay, I got it working in Fuji. This is very long and involved, so if Mr. Stanger wants to format it to make it more pretty, that’s fine.

First step, navigate to cart layouts and find the proper screen. I’m using the two-step, so I go to Maintain Cart Layouts -> Browser Screen -> Cart Preivew Screen (Two Step). This is the cart screen, and it’s made up of UI Macros which compose each section. Now, you don’t want to (and you cannot) update these UI Macros, or you own them. The great thing they’ve done with Fuji is make it easier to update the cart without invalidating upgrade paths, we just have to figure out the rest now. So, take the ui macro sc_cart_view_buttons at order 800. This is the footer buttons, one of which is checkout. Create a new UI Macro, and copy the XML from the sc_cart_view_buttons ui macro over to the new macro (I called my sc_cart_view_buttons_new). Now, go back to the cart screen, select Edit, and remove the sc_cart_view_buttons, then add the sc_cart_view_buttons_new ui macro. Now, make sure you set it to order 800 or 900 or whatever to have it last. Now you can edit this macro (make sure you didn’t just do insert and stay on the OOTB one or it will be protected and read only as well). So, open this macro, find the line for the checkout button:

Change it to this:

Notice the change in the onClick property. We are calling a function, and if that function returns true, then we perform the checkout method.

Now, we have to capture that new function, so go to System UI -> UI Scripts, create a new UI Script. I called mine, much like Mark did above, checkMandatorySubmit. Here, you will actually check to see if the fields you want are populated. I am checking the special_instructions as well as a custom field I’ve added called sc_cart.approver. Make sure to tick the Global checkbox, and below is the code you will need:


function checkMandatorySubmit(parm1, parm2){
//g_form.getValue('sc_cart.approver'),g_form.getValue('special_instructions')
//alert("Here");
var manFields = '';
var si = gel('sc_cart.approver');
//alert("parm1.value is: " + si.value);
if(si.value == ''){
manFields = 'Approver';
}

var si2 = gel('special_instructions');
//alert("parm2.value is: " + si2.value);
if (si2.value == ''){
if (manFields == ''){
manFields = 'Business Justification';
} else {
manFields = manFields + " and Business Justification";
}
}

if(manFields == ''){
return true;
}
else{
alert('The following mandatory fields are not filled in: ' + manFields);
return false;
}

}

Now, that UI Script uses GlideAjax to call a script include. You will need to create this as well. Below is the information on the script include:
Name: cartAjaxProcessor_Custom
Client Callable: Make sure you check this
Script:
var cartAjaxProcessor_Custom = Class.create();

cartAjaxProcessor_Custom.prototype = Object.extendsObject(AbstractAjaxProcessor, {

updateApprover: function(){
var approver = this.getParameter(‘sysparm_value’);
gs.log(“Approver is: ” + approver);

var cart = new GlideRecord(‘sc_cart’);
cart.addQuery(‘user’, gs.getUserID());
cart.addQuery(‘active’, ‘true’);
cart.orderBy(‘sys_created_on’);
cart.query();

if(cart.next()) {
cart.u_approver = approver;
cart.update();
}
}
});

This script include updates the cart so that the cart will grab the new values. For the custom approver field I added, I had to add a field to the cart to hold this. Now that the cart is updated, we need to get this data over to the request. So, on the request, you create a new business rule to pull the data in from the cart. Below is the information on that Business Rule:
Name: Set Approver from Cart
Table: Request [sc_request]
Insert: True
When: before
Script:
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
var user = gs.getUserID();
gs.addInfoMessage(“user is: ” + user);
var gr = new GlideRecord(‘sc_cart’);
gr.addQuery(‘user’, user);
gr.addQuery(‘active’, ‘true’);
gr.orderBy(‘sys_created_on’);
gr.query();

if(gr.next()) {
gs.addInfoMessage(“approver is: ” + gr.u_approver);
current.u_approver = gr.u_approver;
} else {
gs.addInfoMessage(“couldn’t find cart”);
}
}

This should just about do it. I hope this helps you all out, as I know that I spent a very long time figuring this all out.

]]>
By: Junior https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6650 Wed, 23 Sep 2015 21:51:00 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6650 Paul, in the cart layouts, just remove the OOTB macro and create a new one, copy/pasting the OOTB macro’s contents. Then you can edit it freely without stepping on the protection levels.

I think your issue here is that the code has further changed with fuji. Now the onlick is this: “onclick=”checkout(this, forms[‘sc_cart.do’]);””
I’m not sure exactly what all is being done, but it definitely deviates further from what Mr. Stanger had. I am trying to figure this out myself right now, hopefully will find a solution shortly.

]]>
By: Paul https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6649 Tue, 19 May 2015 11:56:49 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6649 Have you planned any updates for this to work in Fuji without editing the base system code?

]]>
By: Dave https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6648 Mon, 29 Sep 2014 08:26:47 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6648 In reply to Mark Stanger.

Mark, works a treat. Thanks

]]>
By: Mark Stanger https://servicenowguru.com/ui-macros/mandatory-fields-service-catalog-checkout/#comment-6647 Fri, 26 Sep 2014 22:08:31 +0000 https://servicenowguru.wpengine.com/?p=985#comment-6647 In reply to Dave.

Looks like SN changed a few things in Eureka. You should be able to fix this by creating a global UI script. I’ve modified the instructions above to reflect this workaround.

]]>