SBX - Search With Button

SBX - Forum Post Title

Possible to update the Owner of an opportunity without clicking "Assign"?

Microsoft Dynamics CRM Forum

tgiard13 asked a question on 6 Mar 2019 4:31 PM

Question Status

Suggested Answer

Is it possible to update the Owner of an opportunity without clicking "Assign"?

I'm wondering if I can use Flow, SQL, or create a workflow process to do this but don't know the best way to go about it.

Thanks!

Reply
Alok Singh responded on 6 Mar 2019 6:44 PM
My Badges
Suggested Answer

Hi ,

If user wants to assign Opportunity to any other user ,they can use Owner field lookup  to select any other user otherwise use workflow to update Owner on change of any field, status etc.

Reply
Wei Jie Fun responded on 6 Mar 2019 7:13 PM
Suggested Answer

Hi,

you can directly update the owner field or using the assign button to transfer the ownership of the record.

Reply
Mahender responded on 6 Mar 2019 7:30 PM
My Badges
Suggested Answer

Hi,

Yes, you can do that, now you can use update method as well to change owner of the record. You may design workflow based on your requirement and use assign step in workflow.

Reply
tgiard13 responded on 17 Apr 2019 10:43 AM

Thank you everyone for your replies.   In QuoteWerks, I have a field called "Prepared by" which I am passing to a created field called "QuoteWerks Prepared By" in my Account entity in Dynamics.  Is it possible to create a workflow that will assign the record to that "QuoteWerks Prepared By" field in my Account entity?  Currently it is has the data type "single line of text" but that can be changed.  If this is not possible, is it possible to pass a GUID to the owner field to reassign it to another user?

Reply
Suggested Answer

Hi

Like I mentioned in the other post, I would recommend you convert QuoteWerks Prepared By to a User Lookup field and create workflow to assign  the record.

Let us know if you need any examples to do this

Reply
tgiard13 responded on 18 Apr 2019 12:32 PM

@Kokulan,

Thank you for the reply.  How can I pass the "Prepared By" field from QuoteWerks to a lookup field?  I don't believe it is possible but maybe I am wrong about that.  That is the field that needs to be assigned as the Owner of the record in CRM.

Thanks!

Reply
Suggested Answer

Hi

There two ways you could get the Lookup Field value set. Just before you create the opportunity record from QuoteWerks, you can query CRM and get the user id and when you create the opportunity you could set the QuoteWerks Prepared By field value.   I do not know how the integration is done from QuoteWerks to CRM, if it's your code that creates the Opportunity in CRM, you can definitely query and get the user id from CRM before you created the Opportunity. And when you do create the opportunity record, you can set the lookup value.

If this is not an option,  you can let the current set up as is, let the QuoteWerks to set the QuoteWerks Prepared By as text field value.

You could create a Custom Workflow Activity(CWA) that takes the name and returns a lookup value

In the workflow that triggers on Create of the opportunity, you can call this workflow to get the User Lookup value. Results from this CWA can be used in the Assign step to assign the record to Prepared by the user.

Reply
tgiard13 responded on 19 Apr 2019 12:53 PM

@Kokulan,

I am not familiar with Custom Workflow Activities.  Any advice on how I should go about creating this and how I can take the name and return a lookup value?

Thanks again!

Reply

Hi

I should be able to point to some sample code, could you please confirm what value the Prepared By field has in QuoteWerks. Is it user name or full name or email address? we need to use this value to query CRM to get the User Lookup value

Reply
tgiard13 responded on 19 Apr 2019 1:17 PM

Thanks so much!  That would be very helpful.  The "Prepared By" field in QuoteWerks contains a full name.

Reply
Suggested Answer

Hi

I have uploaded solution to the following URL that has the CWA to get the user using full name

This is an unmanaged solution and you have to import into your crm and publish. This has just one component as shown below

Please see below as to how you can use this

How to add the CWA Step in your workflow

Once the step is added, click on the properties and set the full name from prepared by text field value

Just in case if you are not sure of how to get the condition right, please see below

And following is the code for the CWA, if you are interested in it.

namespace KED365.Workflows
{
using System;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
using System.Linq;

public sealed class GetUserByFullName : WorkFlowActivityBase
{
[Input("User Full Name")]
public InArgument<string> UserFullName { get; set; }

[Output("Prepared By")]
[ReferenceTarget("systemuser")]
public OutArgument<EntityReference> PreparedBy { get; set; }


[Output("IsSuccess")]
public OutArgument<bool> IsSuccess { get; set; }

[Output("Message")]
public OutArgument<string> Message { get; set; }

protected override void Execute(CodeActivityContext activityContext, IWorkflowContext workflowContext, IOrganizationService CrmService, ITracingService trace)
{
try
{
string userName = UserFullName.Get(activityContext);

if (string.IsNullOrWhiteSpace(userName))
{
IsSuccess.Set(activityContext, false);
Message.Set(activityContext, "User's Full Name is not provided");
return;
}

var QEsystemuser = new QueryExpression("systemuser");
QEsystemuser.ColumnSet.AddColumns("fullname");
QEsystemuser.Criteria.AddCondition("fullname", ConditionOperator.Equal, userName);

var results = CrmService.RetrieveMultiple(QEsystemuser);

if (results == null || !results.Entities.Any())
{
IsSuccess.Set(activityContext, false);
Message.Set(activityContext, "User with " + userName + " not found") ;
return;
}

if (results.Entities.Count > 1)
{
IsSuccess.Set(activityContext, false);
Message.Set(activityContext, "Multiple users found with same name : " + userName);
return;
}


IsSuccess.Set(activityContext, true);
PreparedBy.Set(activityContext, results.Entities.Single().ToEntityReference());
}
catch (Exception ex)
{
IsSuccess.Set(activityContext, false);
Message.Set(activityContext, "An error occurred trying to find user : " + ex.Message);
}
}
}
}

Reply
tgiard13 responded on 19 Apr 2019 4:44 PM

Thank you!  I will definitely give this a try and get back to you.  I apologize as I am still fairly new to CRM, but do I just need to go to Settings --> Solutions --> All Solutions ---> "New", and then upload the GetUserByFullName_1_0_0_0.zip for the CWA step to appear in my default solution?

Reply
Suggested Answer

Hi

You do not need to create new solution. If you click import and then select the zip file it will import it for you and once it's done importing you will have to click publish all. After this the CWA will be available to use in any workflow you create. Please check the screenshots in my above posts

Reply
tgiard13 responded on 22 Apr 2019 1:45 PM

Hi Kokulan,

I imported the CWA and followed your steps but the Owner field is still not updating for some reason.  Do you have some time this week for a quick screen sharing session to help de-bug the issue?

Thanks!

Reply
Suggested Answer

Hi

Could you manually create an opportunity record in crm by setting the Prepared By user full name and save the record and see if the lookup is populated.

The CWA returns a message if it cant set the user lookup value. Could you save this message to a field on opportunity or create a note against the opportunity with this message so that you can find out the reason for why it's not creating it.

Reply
Alok Singh responded on 6 Mar 2019 6:44 PM
My Badges
Suggested Answer

Hi ,

If user wants to assign Opportunity to any other user ,they can use Owner field lookup  to select any other user otherwise use workflow to update Owner on change of any field, status etc.

Reply
Wei Jie Fun responded on 6 Mar 2019 7:13 PM
Suggested Answer

Hi,

you can directly update the owner field or using the assign button to transfer the ownership of the record.

Reply
Mahender responded on 6 Mar 2019 7:30 PM
My Badges
Suggested Answer

Hi,

Yes, you can do that, now you can use update method as well to change owner of the record. You may design workflow based on your requirement and use assign step in workflow.

Reply
Suggested Answer

Hi

Like I mentioned in the other post, I would recommend you convert QuoteWerks Prepared By to a User Lookup field and create workflow to assign  the record.

Let us know if you need any examples to do this

Reply
Suggested Answer

Hi

There two ways you could get the Lookup Field value set. Just before you create the opportunity record from QuoteWerks, you can query CRM and get the user id and when you create the opportunity you could set the QuoteWerks Prepared By field value.   I do not know how the integration is done from QuoteWerks to CRM, if it's your code that creates the Opportunity in CRM, you can definitely query and get the user id from CRM before you created the Opportunity. And when you do create the opportunity record, you can set the lookup value.

If this is not an option,  you can let the current set up as is, let the QuoteWerks to set the QuoteWerks Prepared By as text field value.

You could create a Custom Workflow Activity(CWA) that takes the name and returns a lookup value

In the workflow that triggers on Create of the opportunity, you can call this workflow to get the User Lookup value. Results from this CWA can be used in the Assign step to assign the record to Prepared by the user.

Reply
Suggested Answer

Hi

I have uploaded solution to the following URL that has the CWA to get the user using full name

This is an unmanaged solution and you have to import into your crm and publish. This has just one component as shown below

Please see below as to how you can use this

How to add the CWA Step in your workflow

Once the step is added, click on the properties and set the full name from prepared by text field value

Just in case if you are not sure of how to get the condition right, please see below

And following is the code for the CWA, if you are interested in it.

namespace KED365.Workflows
{
using System;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
using System.Linq;

public sealed class GetUserByFullName : WorkFlowActivityBase
{
[Input("User Full Name")]
public InArgument<string> UserFullName { get; set; }

[Output("Prepared By")]
[ReferenceTarget("systemuser")]
public OutArgument<EntityReference> PreparedBy { get; set; }


[Output("IsSuccess")]
public OutArgument<bool> IsSuccess { get; set; }

[Output("Message")]
public OutArgument<string> Message { get; set; }

protected override void Execute(CodeActivityContext activityContext, IWorkflowContext workflowContext, IOrganizationService CrmService, ITracingService trace)
{
try
{
string userName = UserFullName.Get(activityContext);

if (string.IsNullOrWhiteSpace(userName))
{
IsSuccess.Set(activityContext, false);
Message.Set(activityContext, "User's Full Name is not provided");
return;
}

var QEsystemuser = new QueryExpression("systemuser");
QEsystemuser.ColumnSet.AddColumns("fullname");
QEsystemuser.Criteria.AddCondition("fullname", ConditionOperator.Equal, userName);

var results = CrmService.RetrieveMultiple(QEsystemuser);

if (results == null || !results.Entities.Any())
{
IsSuccess.Set(activityContext, false);
Message.Set(activityContext, "User with " + userName + " not found") ;
return;
}

if (results.Entities.Count > 1)
{
IsSuccess.Set(activityContext, false);
Message.Set(activityContext, "Multiple users found with same name : " + userName);
return;
}


IsSuccess.Set(activityContext, true);
PreparedBy.Set(activityContext, results.Entities.Single().ToEntityReference());
}
catch (Exception ex)
{
IsSuccess.Set(activityContext, false);
Message.Set(activityContext, "An error occurred trying to find user : " + ex.Message);
}
}
}
}

Reply
Suggested Answer

Hi

You do not need to create new solution. If you click import and then select the zip file it will import it for you and once it's done importing you will have to click publish all. After this the CWA will be available to use in any workflow you create. Please check the screenshots in my above posts

Reply
Suggested Answer

Hi

Could you manually create an opportunity record in crm by setting the Prepared By user full name and save the record and see if the lookup is populated.

The CWA returns a message if it cant set the user lookup value. Could you save this message to a field on opportunity or create a note against the opportunity with this message so that you can find out the reason for why it's not creating it.

Reply

SBX - Two Col Forum

SBX - Migrated JS