CA Service Management

Expand all | Collapse all

custom error message

  • 1.  custom error message

    Posted Feb 22, 2017 06:31 AM

    Hello Community,

    I'm searching to get the information on how to customise the error messages.

    In detail, on a form level configuration item field set as required So, when the field is empty the save operation will aborted and throws an error message as "Configuration item is required" i would like to change this particular error message to new one.

    any suggestion how to achieve this?

     

    Thank you,

    Regards,

    Venkat



  • 2.  Re: custom error message

    Posted Feb 22, 2017 08:22 AM

    Hi Venkat, 

    Some of the messaging is stored in the msgcat.js file - what you can do is make a copy of that and put it in site\mods\www\wwwroot\scripts, and then you can customize the messages in that file.  Just do a search for the exact error message that you currently see, and then I believe you can change it in that file.  NOTE that this is NOT A SUPPORTED CUSTOMIZATION and thus CA is not responsible for any side effects of doing this, or maintaining it going forward through patches and upgrades to the product.

    Hope this helps,
    Thanks,

    Jon I.



  • 3.  Re: custom error message

    Posted Feb 22, 2017 10:02 AM

    Hi Jon,

    It looks a bit tricky to me, I suspect there is generic js function which decides and constructs the error message based on the make_required property of the field .

    if we make the make_required property of a form field in detail form  as "make_required=yes " what is the underlying JS function will be called.

    Thanks,

    Venkat



  • 4.  Re: custom error message

    Broadcom Employee
    Posted Feb 22, 2017 10:53 AM

    Venkat, I found the following info and throw out for your info. It is not tested to confirm but I think it should help you...

    take a look at detail_form.js file and function "detailValidate", and this line:

    newmsg = msgtext_with_pfx("%1_is_required", v.hdrtext );

    the "%1_is_required" comes from msg_cat.js  "__messages["%1_is_required"]="%1 is required";"

    so in order to modify the error message, you could either modify the msg_cat mapping or modify the detailValidate function in detail_form.js

    file. Thanks _Chi



  • 5.  Re: custom error message

    Posted Feb 22, 2017 10:59 AM

    Hi,

    Another way may you don't want to do as Jon mention is to create your own by using  presave trigger function to be put in sitemods.js under site\mods\www\wwwroot\scripts folder. see below for an example of prevalidation.

    function preSaveTrigger(){
     element = document.main_form.elements;
     if (typeof element['SET.call_back_date'] == "object"){
    if (typeof element['SET.category'] == "object"){
     var z_callback = element['SET.call_back_date'].value;
     var z_category = element['SET.category'].value;
     var z_callbackid = element['SET.call_back_date'].id;
     var z_callbacktemp = document.getElementById(z_callbackid);
    if ((z_callback == 'undefined' || z_callback == '') && (z_category == 'pcat:402066'|| z_category == 'pcat:402067')){
     detailReportValidation(z_callbacktemp,true,msgtext('1006')); // this is the message number from your msg_cat_site.js you can of course directly hardcode it here
     return false
     }
     else {
     detailReportValidation(z_callbacktemp,false);
    }
    }
    }
    return true
    }

     

    Note that as per the book instructions you supposed to copy the msg_cat_site.js file and not the msg_cat.js file itself  to you site mods folder. 

     

    Hope this help

    /J



  • 6.  Re: custom error message

    Posted Mar 14, 2017 07:04 AM

    Good



  • 7.  Re: custom error message

    Posted Mar 14, 2017 08:34 AM

    Hi Jerome Mayer,

     

    The function validates configuration item value if there is no value for configuration item then It throws an error custom message, but I'm checking on how could i make the filed highlight in  red color.

     

    How could I set "make_required" property to "YES" in JS function?

     

    // Presave Trigger
    function preSaveTrigger()
    {
    if (typeof document.main_form['SET.affected_resource'] == "object")
    {
    var z_affected_service = document.main_form['SET.affected_resource'].value;
    console.log(z_affected_service);
    if ((z_affected_service == 'undefined' || z_affected_service == '')){
    showAlertMsg("*********************");
    return false;
    }
    else{
    return true;
    }
    }

    }

     

    Regards,

    Venkat



  • 8.  Re: custom error message

    Posted Mar 14, 2017 09:46 AM

    Hi CodeGeek,

     

    This is exacltly what my code in example is doing

    You just need to replace your showAlertMsg() by  the detailReportValidation() in my example

     

    detailReportValidation(<the id of element to be verified>,<true or false>,"<your error message>");

     

    True will display the corresponding message and highlight the corresponding field on the form, false will just pass trough.

    Your error message can be hardcoded here or be retrieve from the catalog using the msgtext() function

    Hope this clarify 

    Give it a try and you will see..

     

    Regards,

    Jerome



  • 9.  Re: custom error message

    Posted Mar 14, 2017 09:55 AM

    quickly the code:

     

    function preSaveTrigger(){
     element = document.main_form.elements;
     if (typeof element['SET.affected_resource'] == "object"){
      var z_affected_service = element['SET.affected_resource'].value;
      var z_affected_serviceId = element['SET.affected_resource'].id;
      var z_affected_serviceTemp = document.getElementById(z_affected_serviceId);
       if ((z_affected_service == 'undefined' || z_affected_service == '')){
        detailReportValidation(z_affected_serviceTemp,true,"YOUR MESSAGE HERE");
        return false;
       }
       else{
        detailReportValidation(z_affected_serviceTemp,false);
       }
     }
    return true;
    }
    Hope this help
    /J


  • 10.  Re: custom error message

    Posted Mar 14, 2017 10:48 AM

    Hello JEROME MAYER,

    function preSaveTrigger(){
    element = document.main_form.elements;
    if (typeof element['SET.affected_resource'] == "object"){
      var z_affected_service = element['SET.affected_resource'].value;
      var z_affected_serviceId = element['SET.affected_resource'].id;

    I have checked the developer tools and found out that when I'm creating a new ticket with no Configuration Item then the 'id' property doesn't have the value and it is empty always- so here I'm getting the exception as follows

    Uncaught TypeError: Cannot read property 'id' of null

    at detailReportValidation (detail_form.js:5512)
    at preSaveTrigger (pdmweb.exe:1079)
    at detailSave (detail_form.js:5266)
    at <anonymous>:1:1


     

    var z_affected_serviceTemp = document.getElementById(z_affected_serviceId);

     

    Thank you!

     

    Regards,

    Venkat



  • 11.  Re: custom error message

    Posted Mar 14, 2017 11:33 AM

    was release are you on? and browser you are testing?

    what factory are you working on?

    this technic work fine for me since 12.x (currently on 14.1) on several forms I have, so will require a little troubleshooting.

    Is that possible that your field I not on the form on a new ticket? or inside a <pdm_if>

     

    /J



  • 12.  Re: custom error message

    Posted Mar 16, 2017 06:31 AM

    Hi Jerome,

    • I'm working on 12.9, browser Chrome.
    • working on - cr factory
    • I have placed the code in between <script> section

    moreover, In my testing i have received the error message alert prompt, not as banner error message.

    I will test the below code and post the results.

    Thank you,

    Venkat



  • 13.  Re: custom error message

    Posted Mar 14, 2017 11:34 AM

    if fact looking at the html generated by the detail_in.htmpl and for obvious reason the affected_resource don't have an id vs other field (good practice is always to define one)

     

    <input name="SET.affected_resource" type="hidden" value="">

     

    Then you may want to try to retrieve this element by name either if this is less robust by replacing the lines below:

     

      var z_affected_serviceId = element['SET.affected_resource'].id;
      var z_affected_serviceTemp = document.getElementById(z_affected_serviceId);

    by:

     

    var z_affected_serviceName = element['SET.affected_resource'].name;

    var z_affected_serviceArray = document.getElementByName(z_affected_serviceName);
    var z_affected_serviceTemp = z_affected_serviceArray[0];

     

    Hopefully this name is used only once in your form or is the first one in the code.

    My 2 cents.

    /J