CA Service Management

  • 1.  service catalog get all service names in a request

    Posted Aug 30, 2016 06:46 AM

    Hi All,

     

    I have a request which as multiple services in the cart, I need to fetch all the service names Before submitting. I am using pop up to dispaly that. To fetch all the service name I tried using " _.service.name" service object contains an array of services , but it give the last service name not all. Can anyone suggest how to get all the service names in the request.

     

    Code I used:

     

    var a = _.service.name;
    var all = new Array();
    for(i=0;i<4;i++)
    {
        all[i]=a;
        a++;
    }

    alert(all[0]);
    alert(all[1]);
    alert(all[2]);

    }



  • 2.  Re: service catalog get all service names in a request

    Broadcom Employee
    Posted Sep 19, 2016 07:11 AM

    Hi Shubha,

     

    Is there a missing bracket in code? Just curious if that's not the original issue? Can you concatenate all the values and try to print them just to confirm that its missing iteration and just picking one value?



  • 3.  Re: service catalog get all service names in a request

    Posted Sep 20, 2016 09:38 AM

    HI,

    Missing bracket I didn't get you. Is it _.service.name[] ???

     

    Can you confirm if this out of box js is correct to get all service names??



  • 4.  Re: service catalog get all service names in a request

    Broadcom Employee
    Posted Sep 20, 2016 09:45 AM

    Hi,

     

    I am not aware from where did you fetched this code and also not sure if this is a custom JS code out of the box. Out of coding knowledge I was going through the below code you mentioned and noticed only three brackets and either a opening bracket is missing in this code. Can you confirm if my suspicion true?  

     

    "Code I used:

     

    var a = _.service.name;
    var all = new Array();
    for(i=0;i<4;i++)
    {
        all[i]=a;
        a++;
    }

    alert(all[0]);
    alert(all[1]);
    alert(all[2]);

    }

    "



  • 5.  Re: service catalog get all service names in a request

    Posted Sep 20, 2016 10:01 AM

    HI,

     

    The above code I had written  for testing as I had to get all the service name in the request/cart.

    For example in a request if 2 or more services are added .

    This _.service.name is out of box js which I got from link(https://docops.ca.com/ca-service-management/14-1/en/using/service-catalog-management/manage-forms/perform-automated-tasks-in-form-fields/use-javascript-expressions-in-fields).

    where it is mentioned object contains an array of service name. But I am wondering its fetching last service name in the cart not before one. If not this can you suggest how to get all the service name which is in cart before submitting.

     



  • 6.  Re: service catalog get all service names in a request

    Broadcom Employee
    Posted Sep 20, 2016 12:01 PM

    Hi,

     

    I tried the same code with some static values and got the list of all the values within the variable 'a' . Result is A,B,C  with just one alert i.e. alert(all[0]) results the above values.

     

    Could you print out the length of the service name that you captured in the code? There seems to be some code mismatch here.

     

    <script>
    var a = ["A","B","C"];
    var all = new Array();
    var aLen = a.length;

    for(i=0;i<=aLen;i++)
    {
        all[i]=a;
        a++;
    }

    alert(all[0]);
    //alert(aLen);
    //alert(all[2]);

    </script>



  • 7.  Re: service catalog get all service names in a request
    Best Answer

    Posted Sep 20, 2016 05:12 PM

    Hi Shubha,

     

    Unfortunately, you have found an error in the documentation. However, it is possible to obtain the list of services that are in the cart using the _.scopedVars array of objects

     

     

    Therefore, you should be able to get the name of each service using the following code:

     

    for (key in _.scopedVars) {

    alert(_.scopedVars[key].service.name);

    }

     

    Best regards,

    John

     

    If this reply has correctly answered your question, please click the "Mark Correct" button so others can benefit from this information.



  • 8.  Re: service catalog get all service names in a request

    Posted Sep 23, 2016 06:23 AM

    Thanks alot John, I was able to fetch all the service name in the cart .

    But I tried to get to the estimated cost for the each service it didn't work. I want to know what may be the reason for not getting cost of the service. 

     

    var all = new Array();

    for (key in _.scopedVars)
    {
        all[key]=_.scopedVars[key].service.estimatedCost;
        key++;
    }

    alert(all);



  • 9.  Re: service catalog get all service names in a request

    Posted Sep 23, 2016 02:17 PM

    Hello Shubha,

    As far as I can tell, the estimatedCost field is not used. This makes sense since costs are defined at the more granular Service Option level.

     

    Best regards,

    John