Hi
I believe i can achieve my goal with entity mappings but i think i don't get it till the very end.
I have a table Works that stores Category,Work name, Work price
I have a table Tasks that stores tasks and this table i have a lookup to Category and to Work name to table Works and a Task Price that is a decimal number
What i want to achieve is when creating new task i select work name(lookup from Works) it would automaticaly populate Work price from table Works to this newly creating record to table Taks to field Task price
Task price is Decimal number.
I tried mapping Work price and Task price in Table Works but this does not autopopulate
What i am doing wrong?
Your proposed sollution works! i had mistaken logical name and put id within "" after i fixed all works fine!
@jja You would have got this error when you clear off the field first and then select another value.
Add null check example (if (formContext.getAttribute("new_darbai")) !== null OR undefined)
Hi
This is my generated code and adjustments:
@jja You are looking to prepopulate based on work category you choose which can be done only via JS you have steps already provided.
If you wish to bring the data from Work Entity down to task. First you can map the fields from Work entity to Order entity (you may need to create new fields in order entity). Then map these fields down to Task entity.
Please note that Data type should match between the entities to map.
Now i understand why my mapping doesnt work as i want. It works only from parent entity and i am calling the map from another entity.
Between Works and Tasks I have Order Entity. I create new Order that gets it's number. Then in Orders I have a tab with Subgrid to Tasks. When i hit on it and hit new task it copies me the order number. Then i select Work category, Work task and i expect Price to be prepopulated but it will not because as i understand i am calling this mapping not from the Works entity so this approach will not work.
@Mira_Ghaly i will test your approacj and give a feedback
1. You can need to use the XRM tool Box - Data verse Rest API Builder to create a web api request to get the data from the works like price for example, Example below we need to retrieve Mobile from account so your api request should look like below:
2. Select Request Type= Retrieve Single
3. Choose the Table like works in your case and the fields like Price
4. Then click the XRMweb.api
5. You will be presented with the below javascript:
Xrm.WebApi.online.retrieveRecord("schemanameofworkstable", "GUID of WORKS Place HOlder", "?$select=epd_abn").then(
function success(result) {
console.log(result);
// Columns
var price= result["ShcemaNameofPrice"]; // Text
},
function(error) {
console.log(error.message);
}
);
5. Next step is to get the GUID of the works field to pass to the above function in place of the GUID of WORKS Place HOlder
So to get the ID it should be like below:
function GetWorksPrice(executionContext)
{
var formContext = executionContext.getFormContext();
//This gets the ID you will need to pass the API
var Works = formContext.getAttribute("PLACE Holder for your field name").getValue();
var Id = Works [0].id;
Xrm.WebApi.online.retrieveRecord("schemanameofworkstable", Id , "?$select=epd_abn").then(
function success(result) {
console.log(result);
// Columns
var price= result["ShcemaNameofPrice"]; // Text
},
function(error) {
console.log(error.message);
}
);
}
6. Next you need to set the price field as below:
function GetWorksPrice(executionContext)
{
var formContext = executionContext.getFormContext();
//This gets the ID you will need to pass the API
var Works = formContext.getAttribute("PLACE Holder for your field name").getValue();
var Id = Works [0].id;
Xrm.WebApi.online.retrieveRecord("schemanameofworkstable", Id , "?$select=epd_abn").then(
function success(result) {
console.log(result);
// Columns
var price= result["ShcemaNameofPrice"];
//Set the field on the task
formContext.getAttribute("Place holder for price field name").setValue(lookup);
},
function(error) {
console.log(error.message);
}
);
}
7. Then Go to your Task form in classic mode -> Choose the field Works -> Go to Events Tab and first add your JS file
2. Then Click Add Event
Choose your library and type in your JS Name and tick the pass execution Context
Hope this helps you solve your problem!
Hi @jja ,
Not other than what I put in the link above and this means you would have a tab on your Works table that would be a subgrid of the Tasks table (or the subgrid could be on the same tab) and you would click New Task from this subgrid from the Works table. This would automatically fill in the Works lookup (since you created from the subgrid) and then the mappings (from link above) would map the price into the field.
Hi @jja ,
I usually don't work with JavaScript side so hopefully someone else can help you with that. If you are creating the rows from the parent Works table you can setup mappings that will set this field (see here). This will not work if you are not creating from the parent entity and is only initial mapping.
I know how to create a real time workflow but it will update the price field value only when i hit save button and i want the price to be prepopulated whenever i select work name in Tasks Form when crating new Task. So it is like real time price that is populated directly into the form.
I imagine there should be a evenhandler OnChange set on Form on field Workname. So whenever the lookup field Workname is changed it should execute query to Works table searh for Workname retrieve that work price and set this price to Price field on the form
Hi @jja ,
If I understand the model (depicted below), you should be able to accomplish...
Please try the following:
Some things to think about: