I'm attempting to be able to replace an attribute in CRM with another attribute. Currently they are both option sets, but I need to be able to do this programatically. I am able to download the forms for the entity, search for the attribute, and replace it with a different one, but I'm unsure how to do this in Workflows/Dialogs. Anyone have any idea how to approach it? Anyone have a working code example?
问问题
451 次
1 回答
0
以下是从 SDK更新Dialog 的示例:
/// <summary>
/// Demonstrates how to create, retrieve, update, and delete.
/// a dialog process.</summary>
/// <remarks>
/// At run-time, you will be given the option to delete all the
/// database records created by this program.</remarks>
public class CRUDDialog
{
#region Class Level Members
private Guid _dialogId;
private OrganizationServiceProxy _serviceProxy;
/// <summary>
/// TODO: Change the location and file name of the sample XAML file
/// containing the dialog definition.
/// e.g. Use the sample xml file located in the SDK\SampleCode\CS\Dialogs folder.
/// </summary>
String pathToXAML = Path.Combine(Environment.CurrentDirectory, @"CallCategorization.xml");
#endregion Class Level Members
#region How-To Sample Code
/// <summary>
/// This method first connects to the Organization service. Afterwards,
/// create, retrieve, update, and delete operations are performed on a
/// dialog process.
/// </summary>
/// <param name="serverConfig">Contains server connection information.</param>
/// <param name="promptforDelete">When True, the user will be prompted to delete all
/// created entities.</param>
public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
{
try
{
// Connect to the Organization service.
// The using statement assures that the service proxy will be properly disposed.
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.Device
{
// This statement is required to enable early-bound type support.
_serviceProxy.EnableProxyTypes();
CreateRequiredRecords();
// Define an anonymous type to define the possible values for
// workflow category
var WorkflowCategory = new
{
Workflow = 0,
Dialog = 1
};
// Instantiate a Workflow object.
// See the Entity Metadata topic in the SDK documentation to determine
// which attributes must be set for each entity.
Workflow sampleDialog = new Workflow
{
Category = new OptionSetValue((int)WorkflowCategory.Dialog),
Name = "Sample Dialog: Call Categorization",
PrimaryEntity = PhoneCall.EntityLogicalName,
//Language code for U.S. English
LanguageCode = 1033,
Xaml = File.ReadAllText(pathToXAML)
};
// Create a dialog record.
_dialogId = _serviceProxy.Create(sampleDialog);
Console.Write("{0} created,", sampleDialog.Name);
// Activate the dialog.
SetStateRequest activateRequest = new SetStateRequest
{
EntityMoniker = new EntityReference(Workflow.EntityLogicalName, _dialogId),
State = new OptionSetValue((int)WorkflowState.Activated),
Status = new OptionSetValue(2)
};
_serviceProxy.Execute(activateRequest);
Console.WriteLine(" and activated.");
// Retrieve the dialog containing several of its attributes.
ColumnSet cols = new ColumnSet("name", "statecode", "statuscode");
Workflow retrievedDialog = (Workflow)_serviceProxy.Retrieve(Workflow.EntityLogicalName, _dialogId, cols);
Console.Write("Retrieved,");
// Update the dialog.
// Deactivate the dialog before you can update it.
SetStateRequest deactivateRequest = new SetStateRequest
{
EntityMoniker = new EntityReference(Workflow.EntityLogicalName, _dialogId),
State = new OptionSetValue((int)WorkflowState.Draft),
Status = new OptionSetValue(1)
};
_serviceProxy.Execute(deactivateRequest);
// Retrieve the dialog record again to get the unpublished
// instance in order to update.
Workflow retrievedDialogDeactivated = (Workflow)_serviceProxy.Retrieve(Workflow.EntityLogicalName, _dialogId, cols);
// Update the dialog.
retrievedDialogDeactivated.Name = "Updated Dialog: Call Categorization";
_serviceProxy.Update(retrievedDialogDeactivated);
Console.Write(" updated,");
// Activate the dialog.
SetStateRequest updateActivateRequest = new SetStateRequest
{
EntityMoniker = new EntityReference(Workflow.EntityLogicalName, _dialogId),
State = new OptionSetValue((int)WorkflowState.Activated),
Status = new OptionSetValue(2)
};
_serviceProxy.Execute(updateActivateRequest);
Console.WriteLine(" and activated again.");
DeleteRequiredRecords(promptforDelete);
}
}
// Catch any service fault exceptions that Microsoft Dynamics CRM throws.
catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
{
// You can handle an exception here or pass it back to the calling method.
throw;
}
}
}
希望有帮助。
编辑:
// Update the dialog.
// Deactivate the dialog before you can update it.
SetStateRequest deactivateRequest = new SetStateRequest
{
EntityMoniker = new EntityReference(Workflow.EntityLogicalName, _dialogId),
State = new OptionSetValue((int)WorkflowState.Draft),
Status = new OptionSetValue(1)
};
_serviceProxy.Execute(deactivateRequest);
// Retrieve the dialog record again to get the unpublished
// instance in order to update.
Workflow retrievedDialogDeactivated = (Workflow)_serviceProxy.Retrieve(Workflow.EntityLogicalName, _dialogId, cols);
// Update the dialog.
retrievedDialogDeactivated.Name = "Updated Dialog: Call Categorization";
_serviceProxy.Update(retrievedDialogDeactivated);
Console.Write(" updated,");
虽然它只是更新对话框的名称,但我确信它可以应用于该对话框的任何部分。
于 2015-02-03T18:36:07.023 回答