Answered by:
update attribute problem in dynamics crm 2015 form

Question
-
Hello,
I created a plugin which calculated new value of an attribute and add it to the entity, after the form onsave event is called .
now i need to take this value from form onload event. I always have null value.
But on the plugin log i had the good value.
Thanks for your help
Here is a sample:
if(Xrm.Page.ui.getFormType()==1){
var site=Xrm.Page.getAttribute("access_sitesharepoint");alert (site.getValue());
}
if( context.InputParameters["Target"] isEntity)
{
Entityentity = (Entity)context.InputParameters["Target"];
//si l'entité obtenue n'est pas un compte
if(entity.LogicalName.Equals("account"))
{
//end if
Guidkey = (Guid)entity.Attributes["accountid"];
if(entity.Contains("other_attribute"))
{
entity.Attributes.Add(
"my_attribute", "https://..../"+ key.ToString());
}
}
Thursday, March 24, 2016 1:20 PM
Answers
-
So the answer is easy. Change Execution Mode to Synchronous and Stage to Pre-Validation or Pre-Operation.
Also remove this check - if(Xrm.Page.ui.getFormType()==1){
because your value will be populated when record is saved and this means that getFormType() will return 2 (Edit mode).
Dynamics CRM MVP
Read My blog
Subscribe for one of my courses- Proposed as answer by Andrii ButenkoMVP, Moderator Friday, March 25, 2016 8:58 AM
- Marked as answer by dc74 Friday, March 25, 2016 10:58 AM
Friday, March 25, 2016 8:57 AMModerator
All replies
-
Hello,
In your JavaScript you try to access value access_sitesharepoint field and I don't see where you populate this field in plugin. I believe you haven't posted full code or missed something in it.
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesThursday, March 24, 2016 1:46 PMModerator -
thanks Andrii, i had access_sitesharepoint in plug_in, i just changed it when i posted on the forum. In my script and my plugin don't have my_attribute, or other_attribute. my_attribute is replaced by access_sitesharepoint.
Regards
Thursday, March 24, 2016 2:00 PM -
Hello,
I created a plugin which calculated new value of an attribute and add it to the entity, after the form onsave event is called .
now i need to take this value from form onload event. I always have null value.
But on the plugin log i had the good value.
Thanks for your help
Here is a sample:
if(Xrm.Page.ui.getFormType()==1){
var site=Xrm.Page.getAttribute("my_attribute");alert (site.getValue());
}
if( context.InputParameters["Target"] isEntity)
{
Entityentity = (Entity)context.InputParameters["Target"];
//si l'entité obtenue n'est pas un compte
if(entity.LogicalName.Equals("account"))
{
//end if
Guidkey = (Guid)entity.Attributes["accountid"];
if(entity.Contains("other_attribute"))
{
entity.Attributes.Add(
"my_attribute", "https://..../"+ key.ToString());
}
}
- Merged by Andrii ButenkoMVP, Moderator Thursday, March 24, 2016 3:37 PM The same thread
Thursday, March 24, 2016 2:02 PM -
So what issues do you have?
Also please don't create duplicated threads.
Dynamics CRM MVP
Read My blog
Subscribe for one of my courses
- Edited by Andrii ButenkoMVP, Moderator Thursday, March 24, 2016 3:38 PM
Thursday, March 24, 2016 3:35 PMModerator -
hello,
if(Xrm.Page.ui.getFormType()==1){
var site=Xrm.Page.getAttribute("access_sitesharepoint");alert (site.getValue());
}
return null.
I need to have url added to entity in plug-in (
entity.Attributes.Add(
"access_sitesharepoint", "https://..../"+ key.ToString());
which is not null.
Friday, March 25, 2016 8:18 AM -
Just small clarification for you.
Your JavaScript (which is executed during form onload event) is executed before your plugin code.
Plugin code is executed after you click Save button on form. That's why your field doesn't contain any value.
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesFriday, March 25, 2016 8:36 AMModerator -
the plugin code is executed after save button on the form. The javascript is executed before. I tried to make an update in the plugin but i'm in the create process.
Thanks
Regards
- Edited by dc74 Friday, March 25, 2016 8:42 AM replace it to i and made to make
Friday, March 25, 2016 8:39 AM -
Ok. Please post screenshot of step registration from plugin registration tool.
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesFriday, March 25, 2016 8:42 AMModerator -
Friday, March 25, 2016 8:45 AM
-
No screenshot available. Repost it please.
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesFriday, March 25, 2016 8:48 AMModerator -
Friday, March 25, 2016 8:48 AM
-
So the answer is easy. Change Execution Mode to Synchronous and Stage to Pre-Validation or Pre-Operation.
Also remove this check - if(Xrm.Page.ui.getFormType()==1){
because your value will be populated when record is saved and this means that getFormType() will return 2 (Edit mode).
Dynamics CRM MVP
Read My blog
Subscribe for one of my courses- Proposed as answer by Andrii ButenkoMVP, Moderator Friday, March 25, 2016 8:58 AM
- Marked as answer by dc74 Friday, March 25, 2016 10:58 AM
Friday, March 25, 2016 8:57 AMModerator -
thanks i have this issue
here is détails:
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: account With Id = ba299179-72f2-e511-80d9-00155dff1216 Does Not ExistDetail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220891</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>OperationStatus</d2p1:key>
<d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>SubErrorCode</d2p1:key>
<d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>account With Id = ba299179-72f2-e511-80d9-00155dff1216 Does Not Exist</Message>
<Timestamp>2016-03-25T10:15:19.5838229Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText>[CreateSiteSharePoint: CreateSiteSharePoint.UpdateAccount]
[f5696054-a2e6-e511-80d1-00155dff1216: CreateSiteSharePoint.UpdateAccount: Create of account]
</TraceText>
</OrganizationServiceFault>Friday, March 25, 2016 10:18 AM -
Hello,
Do you have such plugin - CreateSiteSharePoint.UpdateAccount? I believe yes. Deactivate it to make your code work.
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesFriday, March 25, 2016 10:24 AMModerator -
the plugin which is executed is CreateSiteSharePoint.UpdateAccount. If i deactivate it how can i do what i want. I have my javascript code and this plugin
thanks
Friday, March 25, 2016 10:28 AM -
Provide full code of your plugin, please.
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesFriday, March 25, 2016 10:47 AMModerator -
i'd need to change a retrieve call method somewhere in the code because i changed step stage.
The solution is into the step stage how u described.
Thanks.
I get the good url value
Regards
- Edited by dc74 Friday, March 25, 2016 12:42 PM sentence error
Friday, March 25, 2016 11:00 AM