updateEntity["new_totalsum"] = new CrmMoney(calculatedvalue); - dynamics-crm

I can not update the webform. To bee updated I have to push the save button two times. I´ve tried with DynamicEntity entity = (DynamicEntity)context.PreEntityImages["PreCalculate"]; DynamicEntity updateEntity = (DynamicEntity)context.InputParameters.Properties["Target"];
... updateEntity["new_totalsum"] = new CrmMoney(calculatedvalue); The problem is it will not bee updated the first time I push the save button. I have registred the image PreCalculate as Preimage and Message: Update; Eventing Pipeline Stage of Excecution: Pre Stage; Execution Mode : Syncronous
What´s wrong? Thanks

You need to write the modified record back into the Target when you're done, so your changed values will be used when writing the record to the database. At the end of your plugin's Execute() method, do
context.InputParameters[ParameterName.Target] = updateEntity;

Related

ServiceNow: How to create a workflow that runs on incident update?

I need to create a workflow which runs any time an incident is created or updated (or one workflow for each).
When I create a workflow and set the "Table" to Incident, it will run every time an incident is created, but it doesn't run when an incident is updated. I've searched through the wiki and read a slideshow talk on workflow creation, but so far no dice.
Thanks.
You would need to create a business rule on the Incident table that would call your workflow each time there is an update:
var updateOwner = new GlideRecord('wf_workflow');
updateOwner.addQuery('name', '<workflow_name>');
updateOwner.query();
if (updateOwner.next()) {
var wf = new Workflow();
var workflowId = '' + updateOwner.sys_id;
var vars = {};
wf.startFlow(workflowId, current, current.operation, vars);
gs.addInfoMessage('Workflow initiated.');
}

Plugin Pre Operation Create - Update field error

My plugin fire on Pre Create operation on Entity X. When trying to update a field on the Entity X using the following code I am getting error:
trEntity = (Entity)context.InputParameters["Target"];
trGuid = (Guid)trEntity.Id;
tr = (Entity)service.Retrieve("EntityX", trGuid,
new ColumnSet(new string[] { "field_a", "field_b" }));
tr["field_a"] = null;
service.Update(tr);
The error I am getting is:
Entity X with Id = 11505683-2292-b537-e311-143710e56fb7 Does Not Exist
Since you are in Pre-Create, the entity doesn't exist yet in the database.
You don't need to explicitly call Update in a Pre event. You can just update the Target entity (trEntity in your case) and the changes you make will be saved with the Create operation. The Target entity is the actual entity that is about to be created, so feel free to update fields directly on the Target in the Pre event.
trEntity = (Entity)context.InputParameters["Target"];
trEntity["field_a"] = null;
How are you creating your service?
This also happens when you try to update a record outside of the current transaction i.e. using a manually created OrganizationServiceProxy instead of using the one provided by IOrganizationServiceFactory.CreateOrganizationService.

Get Crystal Report data in session

I have noticed that crystal report runs the Linq query once again when the page index is changed, means when we load second page from first page?
So just wanted to know if we can get which page is loaded so that we can keep values in session.
Just a hint is required as I am not getting the desired results from Google.
Update:
I am sorry in a hurry I just clicked on a wrong tag.
So the problem is like:
This is my code below which I use fr running my crystal report:
var rpt = new Result();
List<class> lst1 = new DALMethod().Get();
rpt.SetDataSource(lst1);
CRReportViewer.ReportSource = rpt;
When I switch from page one to two or more, this method in DAL is called again taking the same time it took first time to load, so I just want to have the data in session when query runs first time, and next time when I get the page index, then I will show data from session.
Is there a way around by which I can get the page index in this c# code?
I had found the solution, hope this might help someone else:
I was using a generic list as a data source:
As soon as we get to know the page loads for the first time, I mean not a postback, we can initialize a list to be maintained in session.
After showing the report we can add the data source (which is a list type).
On Report page shift data will be taken from session.
if (!IsPostBack)
{
//clear session and create new session
Session["ReportGenericList"] = null;
}
List<class> datasourceLst=null;
if (Session["ReportGenericList"] != null)
{
datasourceLst= (List<class>)Session["ReportGenericList"];
}
else
{
datasourceLst = //call methods to fill datasource
Session["ReportGenericList"] = datasourceLst;
}

Grab System Created Values CRM 2011

I'm facing a problem when I try to grab the Extended Amount Attribute inside the Opportunity Product Line Entity.
As follows my requirements are that upon creation of a an Opportunity Product Line I have a post-create plugin on it which applies a discount onto the extended amount and creates another line, with the new discounted extended amount. When I try to output the value on another field just to check what it gets, I keep getting 0 strangley. My code is as follows:
// Part where I grab the value
Entity entity = (Entity)context.InputParameters["Target"];
Money extenedAmount = (Money)entity["baseamount"];
//Create new line
Entity oppportunity_product = new Entity("opportunityproduct");
oppportunity_product["manualdiscountamount"] = extenedAmount;
service.Create(oppportunity_product);
Is it even possible to grab the amount? Would really much appreciate if someone could help me out here. Thanks in advanace.
After creation, you want to add a post image. Then reference the post image instead of the target.
if (context.PostEntityImages.Contains("PostImage") &&
context.PostEntityImages["PostImage"] is Entity)
{
postMessageImage = (Entity)context.PostEntityImages["PostImage"];
}
else
{
throw new Exception("No Post Image Entity in Plugin Context for Message");
}

CRM 4 entity["name"] = "New value";

How do I update en entity for example: updateEntity["name"] = ":"... I don't understand how i should work with images (pre/post) and "New Steps" pre/post. Please give me some guidlines how I update an entity. Everyting seems to be fine exept the last step... how to update an entity with some value (string). thanks... Fred
Whats wrong with the code below???
// Obtain the target business entity from the input parmameters
DynamicEntity entity = (DynamicEntity)context.PreEntityImages["PreServiceMobile"];// context.InputParameters.Properties["Target"];
DynamicEntity updateEntity = (DynamicEntity)context.InputParameters.Properties["Target"];
updateEntity["name"] = "value";
You can only set values in the input entity during a pre stage plugin. In a post stage plugin, the entity has already been saved. If you need to update the entity in a post stage, you need to call CrmService.Update(entity)

Resources