How to check current item is OrderGuide in Client Script?

Jaeik Lee
Mega Sage

Hi.

I want to make a field display true in a few OrderGuides.

So i want to make onLoad script that check type of catalog item. 

5 REPLIES 5

Sai Shravan
Mega Sage

Hi @Jaeik Lee ,

To check if the current catalog item is an Order Guide in a client script, you can use the g_form object to get the catalog item's type, and then compare it to the value of the Order Guide constant.

function onLoad() {
  var item_type = g_form.getTableName();
  var ORDER_GUIDE_TYPE = "sc_cat_item_guide"; // replace with the actual value of the Order Guide type constant

  if (item_type == ORDER_GUIDE_TYPE) {
    g_form.setDisplay('field_name', true); // replace 'field_name' with the actual name of your field
  } else {
    g_form.setDisplay('field_name', false); // hide the field for other types of catalog items
  }
}


Regards,
Shravan 

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Hi, 

As of today, the above provided method doesn't work.

Instead @Jaeik Lee , use method g_service_catalog.isOrderGuide(), I've tested it and it works (it returns true/false whether you are on a Catalog Item or an Order Guide.


OnLoad Client Script:

 

function onLoad() {
    alert("OG: " + g_service_catalog.isOrderGuide());
}

 

 

Regards,

Simone

How exactly did you test that, as it does not work on the actual order guide only the children of that order guide.  Because in my testing in the order guide itself, it's returns false.

Another wonder of the SN devs and their coding ability.  Imagine removing the table check only to have this nerf'd method.

Hi @Sai Shravan 

i need similar requirment , can you please let me know what is order type constant here?