Javascript question
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
-
seth_coussens Member Ninja IT Monkey ✭✭✭✭Using the Cireson API, this is entirely possible, though you won't actually be opening up a new 'viewModel'. What you can do is pull the required object from the API using a type projection.
For some basic information on type projections look here: https://blogs.technet.microsoft.com/servicemanager/2011/09/19/having-more-fun-with-type-projections-using-objectprojectioncritera/
Now all you need is the ID value of the type projection that you wish to use. The type projection should contain all of the relationships that you will need when working with this object, and shouldn't contain any more than necessary for performance reasons.
You can then use the Cireson api end point /api/V3/Projection/GetProjection or GetProjectionByCriteria.
Documentation on how to use these end points can be found by going to http://myportaladdress/help
Using these you can actually pull the full object with all properties and any desired relationship objects (determined by the type projection you use). We have a few examples that utilize the API over in our downloads section here on the Community.
5 -
seth_coussens Member Ninja IT Monkey ✭✭✭✭Something to be aware of is that the call you are making is actually an asynchronous call. So you can't immediately use the variable after calling the ajax function, as it has to make the request and pull back the data. This will take longer than the code to move to the next line. You can change this in the function to make the call synchronously, or you can modify your code to make it work with the asynchronous call.
The easiest way to work with an asynchronous call is to put all your code inside the success function.
success: function (data){ myObj = data; var someValue = myObj.SomeValue; function(someValue){ //do something cool with someValue }}
5
Answers
For some basic information on type projections look here: https://blogs.technet.microsoft.com/servicemanager/2011/09/19/having-more-fun-with-type-projections-using-objectprojectioncritera/
Now all you need is the ID value of the type projection that you wish to use. The type projection should contain all of the relationships that you will need when working with this object, and shouldn't contain any more than necessary for performance reasons.
You can then use the Cireson api end point /api/V3/Projection/GetProjection or GetProjectionByCriteria.
Documentation on how to use these end points can be found by going to http://myportaladdress/help
Using these you can actually pull the full object with all properties and any desired relationship objects (determined by the type projection you use). We have a few examples that utilize the API over in our downloads section here on the Community.
From what i understand when using the custom task i do not need to add api tokens or so?
The code looks like this.
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.
I get this when i try to convert it to an object.
You can do that by pushing the data out to the console so you can see what is being returned:
The easiest way to work with an asynchronous call is to put all your code inside the success function.