CA Service Management

  • 1.  Create Script to Alert in a Certain Value

    Posted Feb 14, 2018 08:45 AM

    I am a beginner in creating these scripts for automation in service catalog, read some topics about some possible solutions to my customers need but I could not really understand.

     

    The need requested by my client is that, in a select form, when a certain value is selected an alert message is displayed.

     

    In my attempts to create these scripts I came up with the code below which, logically, does not work!

     

    function zAlertSinpa() {
              if (ca_sdm_attr_affected_resource == 'A2FCABF0264073419DB5771A6F0DBEA7'){
                   alert("TEEST!!!!!")
              }

    }

     

    I'm inserting the javascript call into the select form as follows:

    ca_fd.js.zAlertSinpa()

     

    But as I said, it did not work.

     

    Anyone has did this before?



  • 2.  Re: Create Script to Alert in a Certain Value

    Posted Feb 14, 2018 09:47 AM

    I keep making some attempts and I ended up getting into this code, anyway, I still have not been able to get the page to display the alert.

    {
    zAlert: function () {
         var selected = ca_fdGetSelections(ca_fd.formId, 'ca_sdm_attr_affected_resource').value;
         if (selected == '') {
              alert("!!!!!!!!!!")
         }

    }
    }


  • 3.  Re: Create Script to Alert in a Certain Value

    Broadcom Employee
    Posted Feb 14, 2018 10:19 AM

    Good Afternoon diegolimabsb.

    For me, it is not clear whether you are writing scripts in CA Service Desk Manager(SDM) or in/for CA Service Catalog(SC).

    Please check the below information which give you a start in 'scripting' SC-form(s).

    https://docops.ca.com/ca-service-management/14-1/en/using/service-catalog-management/manage-forms/perform-automated-tasks-in-form-fields/use-javascript-functions-in-fields

    Typically, you specify a custom JavaScript function in one of the following:
    -The onSubmit or onLoad attribute of the form attributes
    -The onChange or onValidate attributes of applicable fields
    ....
    To stop unsaved table rows from submitting the request.
    onSubmit script:
    submit : function() {
    if(ca_fdGetSavedNonEmptyTableRowCount(ca_fd.formId, 'tblRecursos2') < 1){ alert('Table must have at least 1 entry');
    return false;
    }
    else
    return true;
    }
    ............
    In OnSubmit attribute of a form, you can put any js function there.
    It will invoke it at the submit point.
    If that function returns true, the request will be submitted.
    If it returns false, it will not be submitted.

    Thanks and kind regards, Louis van Amelsfort.



  • 4.  Re: Create Script to Alert in a Certain Value

    Posted Feb 14, 2018 10:58 AM

    Hi, Louis_van_Amelsfort!

     

    Many thanx for your reply and sorry if I could not be very clear.

     

    Well, I'm trying to create a way to display an alert when the customer selects a particular value in the select form that displays the configuration items.

     

    I figured that by creating an alert script with some conditions, and inserting the call to this script in the select form's onSubmit it would alert when a certain value was selected.

     

    Is there any way to do this?

     

    Like I said, I've never done this before and I'm having a bit of trouble.

     

    Thanks again for responding!



  • 5.  Re: Create Script to Alert in a Certain Value
    Best Answer

    Posted Feb 14, 2018 06:17 PM

    Hi Diego,

     

    You should be able to leverage something similar to the following:

    alertSelect:function(){
        alert('alertSelect() invoked');
        var selected = ca_fdGetSelectedOptionValues(ca_fd.formId,'users2');
        if (selected =='spadmin'){
          alert('Selected value match: '+selected);
        }
        else {
          alert('Selected value mismatch: '+selected);
        }
      }

     

    In this example the _id of my select field is 'users2'.

     

    You can then specify the following from the 'onChange' attribute of the select field to invoke the script when the selected option is changed:

     

    ca_fd.js.alertSelect()

     

    I would also recommend taking a look at Administration > Tools > Links > Form Designer JavaScript API > Select for information on the methods that can be used to interact with select fields.

     

     

    Thanks,
    Jason



  • 6.  Re: Create Script to Alert in a Certain Value

    Posted Feb 15, 2018 09:02 AM

    Hi Jason_Wolfe!

     

    Many many thanx for the help!

     

    That's exactly what I needed!

     

    I apologize again if i cant be so clear in explaining the need.

     

    With this information I was able to understand some of the features and solve my client's request!

     

    Thank you again!



  • 7.  Re: Create Script to Alert in a Certain Value

    Posted Feb 15, 2018 09:28 AM

    You are most welcome Diego, glad to help!