image - Custom Plugin Does Not Execute -- Need Assistance With Some Basic Understanding -


i new crm , have created new autonumber plugin (actually modified existing plugin).

i having issues getting plugin work on crm side.

i have created plugin, , have created create step. confused image creation, , how need go doing this.

also, using localcontext.trace , not sure view information.

can me understanding exact steps need follow implement plugin. include code here in case doing wrong. again, working plugin , modified it. tried follow pattern used previous developer.

fyi -- have purchased crm solution manager utility deployment process, still not having luck.

thanks in advance time.

here code..

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using iccplugin.proxyclasses; using iccplugin.proxyclasses.proxyclasses; using microsoft.xrm.sdk; using microsoft.xrm.sdk.query;  namespace iccplugin {     public class programreportautonumber : pluginbase {         private readonly string imagealias = "programreport";         private new_programreport preimage { get; set; }         private new_programreport postimage { get; set; }         private new_programreport targetentity { get; set; }          private readonly string imagealias_program = "program";         private new_program preimage_program { get; set; }         private new_program postimage_program { get; set; }         private new_program targetentity_program { get; set; }          public programreportautonumber(string unsecure, string secure)             : base(typeof(programreportautonumber), unsecure, secure) {             base.registeredevents.add(new tuple<int, string, string, action<localplugincontext>>((int)crmpluginstepstage.preoperation, "create", "new_programreport", new action<localplugincontext>(execute)));             //base.registeredevents.add(new tuple<int, string, string, action<localplugincontext>>((int)crmpluginstepstage.postoperation, "update", "new_programreport", new action<localplugincontext>(execute)));             //base.registeredevents.add(new tuple<int, string, string, action<localplugincontext>>((int)crmpluginstepstage.postoperation, "delete", "new_programreport", new action<localplugincontext>(execute)));         }          protected void execute(localplugincontext localcontext) {             if (localcontext == null) {                 throw new argumentnullexception("localcontext");             }              ipluginexecutioncontext context = localcontext.pluginexecutioncontext;              if (context.preentityimages.contains(imagealias) && (context.preentityimages[imagealias] entity)) {                 preimage = new new_programreport((entity)context.preentityimages[imagealias]);             }              if (context.postentityimages.contains(imagealias) && (context.postentityimages[imagealias] entity)) {                 postimage = new new_programreport((entity)context.postentityimages[imagealias]);             }              if (context.preentityimages.contains(imagealias_program) && (context.preentityimages[imagealias_program] entity)) {                 preimage_program = new new_program((entity)context.preentityimages[imagealias_program]);             }              if (context.postentityimages.contains(imagealias_program) && (context.postentityimages[imagealias_program] entity)) {                 postimage_program = new new_program((entity)context.postentityimages[imagealias_program]);             }              if (context.inputparameters.contains("target") && (context.inputparameters["target"] entity)) {                 targetentity = new new_programreport((entity)context.inputparameters["target"]);             }              switch (context.messagename) {                 case "create":                     handlecreate(localcontext);                     break;                 case "update":                     handleupdate(localcontext);                     break;                 case "delete":                     handledelete(localcontext);                     break;                 default:                     throw new argumentexception("invalid message name: " + context.messagename);             }         }          private void handledelete(localplugincontext localcontext) {              localcontext.trace("start - iccplugin.programreport.autonumber.handledelete");              try {                 if (preimage == null) {                     throw new exception("iccplugin.programreport.autonumber.handledelete: preimage null, unable process delete message.");                 }                  // todo: add code here implement delete message.              } catch (exception ex) {                 localcontext.trace(string.format("iccplugin.programreport.autonumber.handledelete: exception while processing delete message, error message: {0}", ex.message), ex);                 throw ex;             } {                 localcontext.trace("end - iccplugin.programreport.autonumber.handledelete");             }             return;         }          private void handleupdate(localplugincontext localcontext) {              localcontext.trace("start - iccplugin.programreport.autonumber.handleupdate");              if (preimage == null) {                 string msg = "iccplugin.programreport.autonumber.handleupdate : update step not registered correctly.  unable retrieve pre-operation image using alias" + imagealias;                 localcontext.trace(msg);                 throw new exception(msg);             }              if (postimage == null) {                 string msg = "iccplugin.programreport.autonumber.handleupdate : update step not registered correctly.  unable retrieve post-operation image using alias" + imagealias;                 localcontext.trace(msg);                 throw new exception(msg);             }              if (preimage_program == null) {                 string msg = "iccplugin.program.autonumber.handleupdate : update step not registered correctly.  unable retrieve pre-operation image using alias" + imagealias_program;                 localcontext.trace(msg);                 throw new exception(msg);             }              if (postimage_program == null) {                 string msg = "iccplugin.program.autonumber.handleupdate : update step not registered correctly.  unable retrieve post-operation image using alias" + imagealias_program;                 localcontext.trace(msg);                 throw new exception(msg);             }              try {                 // todo: add code here implement update message.             } catch (exception ex) {                 localcontext.trace(string.format("iccplugin.programreport.autonumber.handleupdate: exception while processing update message, error message: {0}", ex.message), ex);                 throw ex;             } {                 localcontext.trace("end - iccplugin.programreport.autonumber.handleupdate");             }             return;         }          private void handlecreate(localplugincontext localcontext) {             localcontext.trace("start - iccplugin.programreport.autonumber.handlecreate");              if (targetentity == null) {                 string msg = "iccplugin.programreport.autonumber.handlecreate : create step not registered correctly.  unable retrieve target entity using alias target.";                 localcontext.trace(msg);                 throw new exception(msg);             }              try {                 // if target entity not have new_filenumber attribute set set now.                 if (targetentity.new_filenumber != null && targetentity.new_filenumber != "") {                     // log warning message , not change value.                     localcontext.trace("the program report being created has value file number, skipping auto number assignment field.");                 } else {                     setfilenumber(localcontext);                 }                  if (targetentity.new_name != null && targetentity.new_name != "") {                     localcontext.trace("the program report being created has value report number, skipping auto number assignment field.");                 } else {                     setreportnumber(localcontext);                 }             } catch (exception ex) {                 localcontext.trace(string.format("iccplugin.programreport.autonumber.handlecreate: exception while processing create message, error message: {0}", ex.message), ex);                 throw ex;             } {                 localcontext.trace("end - iccplugin.programreport.autonumber.handlecreate");             }             return;         }          private void setfilenumber(localplugincontext localcontext) {             localcontext.trace("start - iccplugin.programreport.autonumber.setfilenumber");             string s_new_filenumberformat = string.empty;             string s_new_reportnumberprefix = string.empty;             string s_new_filenumbercode = string.empty;              try {                 iorganizationservice service = localcontext.organizationservice;                 string filenumbervalue = "";                 emds_autonumbersequence filenumbersequence = null;                  //  ##################################################################################################                 //  05/02/2013  --  bep -- code added following change auto-number file numbering                 //  ##################################################################################################                 //      1 - year/month/sequence                 //              [year]-[month]-[sequence] = [year] current year / [month] current month / [sequence] number series each year & month , resets 1 when month changes                 //      2 - year/pmg/sequence - pmg                  //              [year]-[pmgproducttype][sequence] = [year] current year / [pmgproducttype] 1st letter pmg product type on program report / [sequence] single number series format                 //      3 - year/letter/sequence - esl,var                 //              [year]-[filecode][sequence] = [year] current year / [filecode] new field on program entity / [sequence] number series each format & file code                 //  ##################################################################################################                  localcontext.trace("look @ file number format determine format use auto-number, default 1 if not set");                  if (targetentity_program.new_filenumberformat.tostring() != "") {                     localcontext.trace("a value set new_filenumberformat field, using value.");                     s_new_filenumberformat = targetentity_program.new_filenumberformat.tostring();                 } else {                     localcontext.trace("a value not set new_filenumberformat field, using 1 default.");                     s_new_filenumberformat = "1";                 }                  localcontext.trace("file number format being used = " + s_new_filenumberformat);                  switch (s_new_filenumberformat) {                     case "1":                         #region file format #1                         filenumbervalue = string.format("{0}-{1}", datetime.now.tostring("yy"), datetime.now.tostring("mm"));                          localcontext.trace("building queryexpression retrieve filenumber sequence record.");                          queryexpression qefilenumbersequence_1 = new queryexpression(baseproxyclass.getlogicalname<emds_autonumbersequence>());                         qefilenumbersequence_1.columnset = new columnset(true);                         qefilenumbersequence_1.criteria.addcondition(emds_autonumbersequence.properties.emds_entitylogicalname, conditionoperator.equal, baseproxyclass.getlogicalname<new_programreport>());                         qefilenumbersequence_1.criteria.addcondition(emds_autonumbersequence.properties.emds_attributelogicalname, conditionoperator.equal, new_programreport.properties.new_filenumber);                         qefilenumbersequence_1.criteria.addcondition(emds_autonumbersequence.properties.emds_prefix, conditionoperator.equal, filenumbervalue);                          localcontext.trace("getting filenumber sequence record.");                          list<emds_autonumbersequence> lfilenumbersequences_1 = service.retrieveproxies<emds_autonumbersequence>(qefilenumbersequence_1);                         if (lfilenumbersequences_1 == null || lfilenumbersequences_1.count == 0) {                             localcontext.trace("no filenumber sequence record returned, creatign new one.");                              // no matching sequence records.  lets start new sequence index record month , year.                             filenumbersequence = new emds_autonumbersequence();                             filenumbersequence.emds_attributelogicalname = new_programreport.properties.new_filenumber;                             filenumbersequence.emds_entitylogicalname = baseproxyclass.getlogicalname<new_programreport>();                             filenumbersequence.emds_index = 1;                             filenumbersequence.emds_prefix = filenumbervalue;                             filenumbersequence.emds_name = string.format("file number sequence for: {0}", filenumbervalue);                             filenumbersequence.create(service);                         } else {                             localcontext.trace("a filenumber sequence record found, using it.");                             // file number sequence record returned.  if there happen multiple going use first 1 returned.                             filenumbersequence = lfilenumbersequences_1[0];                         }                         //  ###############################################################################                         //  05/02/2013  --  bep --  changed format "###" "##" seq number                         //  ###############################################################################                         filenumbervalue = string.format("{0}-{1:00}", filenumbervalue, filenumbersequence.emds_index);                         filenumbersequence.emds_index++;                         filenumbersequence.update(service);                         #endregion                         break;                     case "2":                         #region file format #2                          if (targetentity_program.new_reportnumberprefix != null && targetentity_program.new_reportnumberprefix != "") {                             localcontext.trace("a value set new_reportnumberprefix field, using value.");                             s_new_reportnumberprefix = targetentity_program.new_reportnumberprefix;                         } else {                             localcontext.trace("a value not set new_reportnumberprefix field, using p default.");                             s_new_reportnumberprefix = "p";                         }                          filenumbervalue = string.format("{0}-{1}", datetime.now.tostring("yy"), s_new_reportnumberprefix);                          localcontext.trace("building queryexpression retrieve filenumber sequence record.");                          queryexpression qefilenumbersequence_2 = new queryexpression(baseproxyclass.getlogicalname<emds_autonumbersequence>());                         qefilenumbersequence_2.columnset = new columnset(true);                         qefilenumbersequence_2.criteria.addcondition(emds_autonumbersequence.properties.emds_entitylogicalname, conditionoperator.equal, baseproxyclass.getlogicalname<new_programreport>());                         qefilenumbersequence_2.criteria.addcondition(emds_autonumbersequence.properties.emds_attributelogicalname, conditionoperator.equal, new_programreport.properties.new_filenumber);                         qefilenumbersequence_2.criteria.addcondition(emds_autonumbersequence.properties.emds_prefix, conditionoperator.equal, "pmg");                          localcontext.trace("getting filenumber sequence record.");                          list<emds_autonumbersequence> lfilenumbersequences_2 = service.retrieveproxies<emds_autonumbersequence>(qefilenumbersequence_2);                         if (lfilenumbersequences_2 == null || lfilenumbersequences_2.count == 0) {                             localcontext.trace("no filenumber sequence record returned, creatign new one.");                              // no matching sequence records.  lets start new sequence index record month , year.                             filenumbersequence = new emds_autonumbersequence();                             filenumbersequence.emds_attributelogicalname = new_programreport.properties.new_filenumber;                             filenumbersequence.emds_entitylogicalname = baseproxyclass.getlogicalname<new_programreport>();                             filenumbersequence.emds_index = 1;                             filenumbersequence.emds_prefix = "pmg";                             filenumbersequence.emds_name = string.format("file number sequence for: {0}", filenumbervalue);                             filenumbersequence.create(service);                         } else {                             localcontext.trace("a filenumber sequence record found, using it.");                             // file number sequence record returned.  if there happen multiple going use first 1 returned.                             filenumbersequence = lfilenumbersequences_2[0];                         }                         filenumbervalue = string.format("{0}-{1:0000}", filenumbervalue, filenumbervalue + filenumbersequence.emds_index.tostring());                         filenumbersequence.emds_index++;                         filenumbersequence.update(service);                         #endregion                         break;                     case "3":                         #region file format #3                          if (targetentity_program.new_filenumbercode != null && targetentity_program.new_filenumbercode != "") {                             localcontext.trace("a value set new_filenumbercode field, using value.");                             s_new_filenumbercode = targetentity_program.new_filenumbercode;                         } else {                             localcontext.trace("a value not set new_filenumbercode field, using l default.");                             s_new_filenumbercode = "l";                         }                          filenumbervalue = string.format("{0}-{1}", datetime.now.tostring("yy"), s_new_filenumbercode);                          localcontext.trace("building queryexpression retrieve filenumber sequence record.");                          queryexpression qefilenumbersequence_3 = new queryexpression(baseproxyclass.getlogicalname<emds_autonumbersequence>());                         qefilenumbersequence_3.columnset = new columnset(true);                         qefilenumbersequence_3.criteria.addcondition(emds_autonumbersequence.properties.emds_entitylogicalname, conditionoperator.equal, baseproxyclass.getlogicalname<new_programreport>());                         qefilenumbersequence_3.criteria.addcondition(emds_autonumbersequence.properties.emds_attributelogicalname, conditionoperator.equal, new_programreport.properties.new_filenumber);                         qefilenumbersequence_3.criteria.addcondition(emds_autonumbersequence.properties.emds_prefix, conditionoperator.equal, filenumbervalue);                          localcontext.trace("getting filenumber sequence record.");                          list<emds_autonumbersequence> lfilenumbersequences_3 = service.retrieveproxies<emds_autonumbersequence>(qefilenumbersequence_3);                         if (lfilenumbersequences_3 == null || lfilenumbersequences_3.count == 0) {                             localcontext.trace("no filenumber sequence record returned, creatign new one.");                              // no matching sequence records.  lets start new sequence index record month , year.                             filenumbersequence = new emds_autonumbersequence();                             filenumbersequence.emds_attributelogicalname = new_programreport.properties.new_filenumber;                             filenumbersequence.emds_entitylogicalname = baseproxyclass.getlogicalname<new_programreport>();                             filenumbersequence.emds_index = 1;                             filenumbersequence.emds_prefix = filenumbervalue;                             filenumbersequence.emds_name = string.format("file number sequence for: {0}", filenumbervalue);                             filenumbersequence.create(service);                         } else {                             localcontext.trace("a filenumber sequence record found, using it.");                             // file number sequence record returned.  if there happen multiple going use first 1 returned.                             filenumbersequence = lfilenumbersequences_3[0];                         }                         filenumbervalue = string.format("{0}-{1:0000}", filenumbervalue, filenumbervalue + filenumbersequence.emds_index.tostring());                         filenumbersequence.emds_index++;                         filenumbersequence.update(service);                         #endregion                         break;                     default:                         break;                 }                  targetentity.new_filenumber = filenumbervalue;             } catch (exception ex) {                 localcontext.trace(string.format("iccplugin.programreport.autonumber.setfilenumber: exception while setting file number value, error message: {0}", ex.message), ex);                 throw ex;             } {                 localcontext.trace("end - iccplugin.programreport.autonumber.setfilenumber");             }         }          private void setreportnumber(localplugincontext localcontext) {             localcontext.trace("start - iccplugin.programreport.autonumber.setreportnumber");             string s_new_reportnumberprefix = string.empty;              try {                 iorganizationservice service = localcontext.organizationservice;                 string reportnumbervalue = "";                 emds_autonumbersequence reportnumbersequence = null;                  //  ##################################################################################################                 //  05/02/2013  --  bep -- code added following change auto-number file numbering                 //  ##################################################################################################                 //  plugin uses gp class id prefix report number.                   //  needs use report number prefix field.                  //  ##################################################################################################                  if (targetentity_program.new_reportnumberprefix != null && targetentity_program.new_reportnumberprefix != "") {                     localcontext.trace("a value set new_reportnumberprefix field, using value.");                     s_new_reportnumberprefix = targetentity_program.new_reportnumberprefix;                 } else {                     localcontext.trace("a value not set new_reportnumberprefix field, using p default.");                     s_new_reportnumberprefix = "p";                 }                  localcontext.trace("building queryexpression retrieve parent new_program record.");                  //  #################################################################################                 //  05/02/2013  --  bep --  above code replaces need pull gp class id                 //  #################################################################################                 //new_program program = targetentity.new_programid.retrieveproxy<new_program>(service, new columnset(true));                 // going assume able parent program record.  if not exception thrown.                 // add check here , throw our own detailed exception if needed.                  reportnumbervalue = string.format("{0}", s_new_reportnumberprefix);  // using trim safe.                  // lets sequence record report number prefix                 queryexpression qereportnumbersequence = new queryexpression(baseproxyclass.getlogicalname<emds_autonumbersequence>());                 qereportnumbersequence.columnset = new columnset(true);                 qereportnumbersequence.criteria.addcondition(emds_autonumbersequence.properties.emds_entitylogicalname, conditionoperator.equal, baseproxyclass.getlogicalname<new_programreport>());                 qereportnumbersequence.criteria.addcondition(emds_autonumbersequence.properties.emds_attributelogicalname, conditionoperator.equal, new_programreport.properties.new_name);                 qereportnumbersequence.criteria.addcondition(emds_autonumbersequence.properties.emds_prefix, conditionoperator.equal, reportnumbervalue);                  localcontext.trace("getting report number sequence record.");                  list<emds_autonumbersequence> lreportnumbersequences = service.retrieveproxies<emds_autonumbersequence>(qereportnumbersequence);                 if (lreportnumbersequences == null || lreportnumbersequences.count == 0) {                     localcontext.trace("no report number sequence record returned, creatign new one.");                      // no matching sequence records.  lets start new sequence index record month , year.                     reportnumbersequence = new emds_autonumbersequence();                     reportnumbersequence.emds_attributelogicalname = new_programreport.properties.new_name;                     reportnumbersequence.emds_entitylogicalname = baseproxyclass.getlogicalname<new_programreport>();                     reportnumbersequence.emds_index = 1;                     reportnumbersequence.emds_prefix = reportnumbervalue;                     reportnumbersequence.emds_name = string.format("report number sequence report number prefix: {0}", reportnumbervalue);                     reportnumbersequence.create(service);                 } else {                     localcontext.trace("a report number sequence record found, using it.");                     // file number sequence record returned.  if there happen multiple going use first 1 returned.                     reportnumbersequence = lreportnumbersequences[0];                 }                  reportnumbervalue = string.format("{0}-{1}", reportnumbervalue, reportnumbersequence.emds_index);                 reportnumbersequence.emds_index++;                 reportnumbersequence.update(service);                  targetentity.new_name = reportnumbervalue;             } catch (exception ex) {                 localcontext.trace(string.format("iccplugin.programreport.autonumber.setreportnumber: exception while setting file number value, error message: {0}", ex.message), ex);                 throw ex;             } {                 localcontext.trace("end - iccplugin.programreport.autonumber.setreportnumber");             }         }     } } 

this response to:

i using localcontext.trace , not sure view information

from msdn; debug plug-in - logging , tracing

during execution , when plug-in passes exception platform @ run-time, tracing information displayed user. synchronous registered plug-in, tracing information displayed in dialog box of microsoft dynamics crm web application. asynchronous registered plug-in, tracing information shown in details area of system job form in web application.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -