Dynamic CRM 2013 study notes (5) prohibit modification of approved documents

Source: Internet
Author: User
Tags microsoft dynamics

Dynamic CRM 2013 learning notes (1) plugin input entity Parameter Parsing

Dynamic CRM 2013 study notes (2) Basic plug-in usage and debugging

Dynamic CRM 2013 learning notes (3) quick creation of entity entitycreater

Dynamic CRM 2013 learning notes (4) Document No. and plug-in batch registration tools

 

 

After the approval, you generally need to control the approved documents, such as the documents that cannot be modified, cannot be added, or deleted. The following describes how to implement them:

 

1. Modification prohibited:

1. master table control. If the approval status on the page is approval or approved, the entire page will be disable

  1: function controlReadonly() {
  2:     var status = Xrm.Page.data.entity.attributes.get("new_approval_status").getValue();
3: If (status = 2 | status = 3) // approved or approved
  4:     {
  5:         var controls = Xrm.Page.ui.controls.get();
  6:         for (var i in controls) {
  7:             var control = controls[i];
  8:             control.setDisabled(true);
  9:         }
 10:     }
 11: }

2. Sub-table control. If a sub-table exists, make sure it cannot be modified.

First, find the approval status of the master table. If it is approved or approved, disable the entire sub-table.

  1: function disableSubForm() {
  2:     var marketingPlan = Xrm.Page.getAttribute("new_marketing_planid").getValue();
  3:     if (marketingPlan != null) {
  4:         var filter = "new_marketing_planSet?$select=new_approval_status&$filter=new_marketing_planId eq guid‘" + marketingPlan[0].id + "‘";
  5:         var status = Query_ent(filter);
  6:         if (status != null && status.new_approval_status != null) {
  7:             if (status.new_approval_status.Value == 3 || status.new_approval_status.Value == 2) {
  8:                 controlReadOnly();
  9:             }
 10:         }
 11:     }
 12: }
 

Ii. Do not add or delete sub-table records

Through the above JS control, all the fields on the page are indeed disable, but the add and delete buttons on the subtable subgrid and subtable page are not controlled. Therefore, we decided to write a General Plug-in to control addition and deletion.
1. shows how to register this General Plug-in on the master table
 

Here, the message is delete, which controls the Delete; if it is create, it must be setPost-operationTo control the addition.

The focus is on the configuration of the unsecure configuration on the right:

  • Input Condition

<Filter type = "or">
<Condition attribute = "new_approval_status" operator = "EQ" value = "2"/>
<Condition attribute = "new_approval_status" operator = "EQ" value = "3"/>
</Filter>

  • If this condition is met, this error is reported.

<Check error = "Cannot delete when approval status is approving or approved! ">

 

2. subtable Registration

The sub-table does not have the approval status field. This field only exists in the master table, but must be dependent on this field to control the sub-table. What should I do?

You must specify the following configurations:

  1: <check error="Cannot delete sub-form when main form is approving or approved!">    
  2:  <link-entity name="new_marketing_plan" to="new_marketing_planid">        
  3:   <filter type="or">            
  4:    <condition attribute="new_approval_status" operator="eq" value="2" />            
  5:    <condition attribute="new_approval_status" operator="eq" value="3" />        
  6:   </filter>    
  7:  </link-entity>
  8: </check>
A Brief Introduction of the configuration here, compared with the configuration of the master table, there is only one more link-entity:
<link-entity name="new_marketing_plan" to="new_marketing_planid">   
Name refers to the entity of the master table, and to refers to the fields link from the child table to the entity of the master table.
 

Iii. Technical Implementation

1. Read the configuration in unsecure configuration through a constructor of the Parameter
  1: public EntityCheck(string unsecure)
  2: {
  3:     m_Config = unsecure;
  4: }
The Microsoft Dynamics CRM platform supports an optional plug-in constructor that accepts one or two string parameters. If you write such constructor, you can pass any information string to the plug-in at runtime.
The following example shows the format of the constructor. In this example, the plug-in class is named sampleplugin.
public SamplePlugin()public SamplePlugin(string unsecure)public SamplePlugin(string unsecure, string secure)

The first string parameter of the constructor contains public (Insecure) information. The second string parameter contains non-public (secure) information. Here, security refers to the encrypted value, while uneasiness refers to the unencrypted value. If you use Microsoft Dynamics CRM for Microsoft Office outlook with offline access, the security string is not passed to the executed plug-in when CRM for outlook is offline.

The information passed to the plug-in constructor in these strings is specified when the plug-in is registered in Microsoft Dynamics CRM. When using the plug-in registration tool to register a plug-in, you can enter the Security Information and insecure information in the "Security Configuration" and "insecure configuration" fields provided in the "register a new step" form. When you use Microsoft Dynamics crm sdk to register a plug-in programmatically,Sdkmessageprocessingstep. ConfigurationContains insecure values,Sdkmessageprocessingstep. secureconfigidReferenceSdkmessageprocessingstepsecureconfigRecord.

 
2. Read link-entity
  1: XmlNodeList linkEntityNodeList = linkEntityNode.SelectNodes("link-entity");
  2: if (linkEntityNodeList != null)
  3: {
  4:     foreach (XmlNode subLinkEntityNode in linkEntityNodeList)
  5:     {
  6:         LinkEntity subLe = GetLinkEntity(subLinkEntityNode);
  7:         le.LinkEntities.Add(subLe);
  8:     }
  9: }
 
3. read filter from config
  1: XmlNodeList filterNodeList = linkEntityNode.SelectNodes("filter");
  2: if (filterNodeList != null)
  3: {
  4:     foreach (XmlNode filterNode in filterNodeList)
  5:     {
  6:         FilterExpression filter = this.GetFilter(filterNode);
  7: 
  8:         le.LinkCriteria.AddFilter(filter);
  9:     }
 10: }
 
4. Read condition from config
  1: XmlNodeList conditionNodeList = linkEntityNode.SelectNodes("condition");
  2: if (conditionNodeList != null)
  3: {
  4:     foreach (XmlNode conditionNode in conditionNodeList)
  5:     {
  6:         ConditionExpression condition = this.GetCondition(conditionNode);
  7: 
  8:         le.LinkCriteria.AddCondition(condition);
  9:     }
 10: }
 
5. Finally, a queryexpression object is merged and passed into the retrievemultiple Method for query. If a record exists, an error is thrown:
  1: EntityCollection ec = AdminService.RetrieveMultiple(config.Query);
  2: if (ec != null && ec.Entities.Count > 0)
  3: {
  4:     throw new InvalidPluginExecutionException(config.Error);
  5: }

Dynamic CRM 2013 study notes (5) prohibit modification of approved documents

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.