Home Analyst Portal

Javascript question

Thomas_StrombergThomas_Stromberg Premier Partner Advanced IT Monkey ✭✭✭
Hi i am working on a solution to send out an email to all child WI from the parent WI. And i have come across an issue.

In order to get the email-addresses from all child objects i need to have the pageForm.viewModel.RequestedWorkItem.BaseId information from each child WI. However that information is not available in the pageForm.viewModel.ChildWorkItem

Now to the question. Is it possible to open up a new viewModel based on baseId from the ChildWorkItem so i can access the RequestedWorkItem.BaseId?

Best Answers

Answers

  • Thomas_StrombergThomas_Stromberg Premier Partner Advanced IT Monkey ✭✭✭
    Thanks for the response, i manage to pull the information i wanted using the API. However i have done this using the debug console in Chrome and that works fine and so. But when i add it to custom.js the data does not seems to be pulled. 

    From what i understand when using the custom task i do not need to add api tokens or so?

    The code looks like this.

    var IncidentID = pageForm.viewModel.ChildWorkItem[0].Id
    var myJason;
    $.ajax({
    //alert("Incident ID" + IncidentID)
    url: "/api/V3/Projection/GetProjection?id=" + IncidentID + " +&typeProjectionId=2d460edd-d5db-bc8c-5be7-45b050cba652",
    type: "GET",
    success: function (json) {
    myJason = json;
    }
    });
    In Crome i can access the myJason information with no problem with this myJason.RequestedWorkItem.BaseId
    and in the portal i get this error. 
    Uncaught TypeError: Cannot read property 'RequestedWorkItem' of undefined

    It's the exact same code just ran two different ways. 
  • seth_coussensseth_coussens Member Ninja IT Monkey ✭✭✭✭
    You need to convert the json to an object based on the code I see above. Currently it's returned as JSON which is actually just text. Chrome does some formatting on it for you visually, but as far as the code is concerned it's still just text.

    success: function (data) {   myObject = JSON.parse(data);}
  • Thomas_StrombergThomas_Stromberg Premier Partner Advanced IT Monkey ✭✭✭
    From what i can see i cannot parse it due to the fact it's already a object. I can turn it to a string without any problem. 

    I get this when i try to convert it to an object.
    Uncaught SyntaxError: Unexpected token o in JSON at position 1


  • seth_coussensseth_coussens Member Ninja IT Monkey ✭✭✭✭
    Sorry, you are correct. jQuery will bring the data back as an object already. The next step is to see if the information you are looking for exists in the data that is coming back.

    You can do that by pushing the data out to the console so you can see what is being returned:
    success: function (data){   console.log(data);}
  • Thomas_StrombergThomas_Stromberg Premier Partner Advanced IT Monkey ✭✭✭
    Yep, i do get the correct information. But i can't use it outside Chrome debugging :( It seems that my variable does not save the data when running outside the debugging tool. 
  • Thomas_StrombergThomas_Stromberg Premier Partner Advanced IT Monkey ✭✭✭
    Aha, i think you just solved my problem. That explains why i could not use it. Will create some functions to fix the code. 
This discussion has been closed.