Dynamic CRM 2013 Learning Notes (v) Prohibition of modification of documents after approval

Source: Internet
Author: User
Tags first string microsoft dynamics

After the approval of the document, generally to control it, can not be modified, can not be added, delete, etc., the following separately describes how to achieve:

I. Prohibition of modification:

1. master Table control, if the approval status on the page is approved or approved, the entire page will be disable off

  function controlreadonly () {
  2:     var status = Xrm.Page.data.entity.attributes.  Get("new_approval_status"). GetValue ();
  3:     if (status = = 2 | | status = = 3)//approval or approval
  4:     {
  5:         var controls = Xrm.Page.ui.controls.  Get();
  6: For in          controls) {
  7:             var control = controls[i];
  8:             control.setdisabled (true);
  9:         }
Ten:     }
11:}

2. Child table control, if there is a child table, also let it cannot be modified

First find the approval status of the primary table, if it is approved or approved, disable the entire child table

  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:             }
Ten:         }
One:     }
12:}

Second, prohibit the addition and deletion of sub-table records

Through the above JS control, all the fields on the page are disable, but the subgrid of the child table and the Add and delete buttons on the child table page are not controlled. So decided to write a generic plugin to control the addition and deletion.
1. Shows how to register this generic plugin on the main table
 
 

The message here is delete, which controls the delete, and if it is create, it is set to post-operationto control the addition.

The focus is on the unsecure configuration of the right:

  • Passed in 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, the error is reported.

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

2. Registering on a child table

There is no approval status on the child table, this field is only available on the main table, but also depends on this field to control the child table, what should I do?

You should specify the following configuration:

  Error= "cannot delete sub-form when main form is approving or approved!" >    
  2:  <link-entity name= "New_marketing_planto ="New_marketing_planid">        
  3:   <filter type= "or" >            
  4:    <condition attribute= "new_approval_statusoperator="eq"value="2 "/>            
  5:    <condition attribute= "new_approval_statusoperator="eq"value="3 "/>        
  6:   </filter>    
  7:  </link-entity>
  8: </check>
A brief introduction to the configuration here, compared to the configuration of the main table, just a few more link-entity:
Name refers to the entity of the primary table, to refers to the field in the child table that link to the main table entity

Third, the realization of technology

1. Read the configuration in unsecure config by a constructor of a parameter
   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 arguments. If you write such a constructor, you can pass any information string to the plug-in at run time.
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 a constructor contains public (unsafe) information. The second string parameter contains non-public (security) information. In this case, security refers to the value of the encryption, but not security refers to unencrypted values. If you use Microsoft Dynamics CRM for Microsoft Office Outlook with offline access, the security string is not passed to the executing 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 registering a plug-in using the plug-in registration tool, you can enter security information and unsafe information in the security configuration and insecure configuration fields provided in the register new steps form. When you register a plug-in programmatically by using the Microsoft Dynamics CRM SDK,sdkmessageprocessingstep.configuration contains unsafe values . Sdkmessageprocessingstep.secureconfigid references a sdkmessageprocessingstepsecureconfig record that contains a safe value.

2. Read Link-entity
  1:xmlnodelist linkentitynodelist = Linkentitynode.selectnodes ("link-entity");
  if (linkentitynodelist! = null)
  3: {
  4: 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:} 
 Ten:} 
   
 4. read from config condition 
 1:xmlnodelist conditionnodelist = Linkentityno De.
 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:} 
 Ten:} 
 
  
5. Finally, a QueryExpression object is synthesized, passed into the RetrieveMultiple method, queried, and throws an error if there is a record present:
  1:entitycollection EC = adminservice.retrievemultiple (config. Query);
  if (EC! = NULL && EC. Entities.count > 0)
  3: {
  4:     thrownew invalidpluginexecutionexception (config.  Error);
  5:}

Dynamic CRM 2013 Learning Notes Series Rollup

Dynamic CRM 2013 Learning Notes (v) Prohibition of modification of documents after approval

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.