The Programmatic Refresh of Meta Data using COM ASP API

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

The Programmatic Refresh of Meta Data using COM ASP API

  • Comments 1
  • Likes

This article will discuss 


1) 2 methods to programmatically control the refresh of meta data.
2) The display of the old style workflow configuration screen that governs the marketing workflow

Background

The existing workflow rules for the marketing tables (Campaigns, Waves and WaveItems) are actually derived from an older way of creating workflow. I cover this in detail on the Development Partner course.

What I want to do here is create a convenient way of exposing the configuration of those rules within the interface. See the screen shot below:



I have added an ASP page under the System menu

Administration -> System

  
The Code of the page contains:


if(CRM.Mode==View)
{
CRM.Mode = Edit;
}

var myBlock = CRM.GetBlock("entrygroup");
var EnableOldWorkflowBlock = CRM.GetBlock("entry");
with(EnableOldWorkflowBlock)
{
EntryType = 21;
Caption = "Enable Old Workflow Config";
DefaultValue = CRM.SystemOption("EnableOldWorkflowConfig");
FieldName = "EnableOldWorkflowConfig";
LookUpFamily = "YesNo"
Size = 1;
NewLine = false;
}

with (myBlock)
{
Title = CRM.GetTrans("GenCaptions", "System Behaviour");
AddBlock(EnableOldWorkflowBlock);
}

CRM.AddContent(myBlock.Execute());

if (CRM.Mode==Save)
{
//Retrieve Record
var EnableOldWorkflowRecord = CRM.FindRecord("custom_sysparams","parm_name='EnableOldWorkflowConfig'");
EnableOldWorkflowRecord.parm_value = Request.Form("EnableOldWorkflowConfig");
EnableOldWorkflowRecord.SaveChanges();

CRM.RefreshMetaData();
//Response.Redirect(eWare.URL(760)+"&ExecuteRefresh='Yes'&RefreshSystemParameters='Y'");
Response.Redirect(CRM.URL(1650)+"&MenuName=AdminAdvanced&BC=Admin,Admin,AdminAdvanced,Advanced Customization");
}

Response.Write(CRM.GetPage("None"));


This produces the screen



There are a few sections of the code that are worth noting:

a)

var EnableOldWorkflowBlock = eWare.GetBlock("entry");
with(EnableOldWorkflowBlock)
{
EntryType = 21;
Caption = "Enable Old Workflow Config";
DefaultValue = CRM.SystemOption("EnableOldWorkflowConfig");
FieldName = "EnableOldWorkflowConfig";
LookUpFamily = "YesNo"
Size = 1;
NewLine = false;
}

The code here is building a screen without reference to meta data. 

Here I have used a very simple way of obtaining the value of the System Parameter.

b)

I changed the value of the system parameter using this code:

var EnableOldWorkflowRecord = CRM.FindRecord("custom_sysparams","parm_name='EnableOldWorkflowConfig'");
EnableOldWorkflowRecord.parm_value = Request.Form("EnableOldWorkflowConfig");
EnableOldWorkflowRecord.SaveChanges();

But no change would be made in the current system behaviour unless the meta data was refreshed within the memory of the application server.

c)

To refresh the meta data I can either use the

CRM.RefreshMetaData();
Response.Redirect(CRM.URL(1650)+"&MenuName=AdminAdvanced&BC=Admin,Admin,AdminAdvanced,Advanced Customization");

or

Response.Redirect(CRM.URL(760)+"&ExecuteRefresh='Yes'&RefreshSystemParameters='Y'");

The CRM.RefreshMetaData() method can accept a translation caption family as a parameter, e.g. CRM.RefreshMetaData("addr_country"), but here I have not used a parameter to limit the meta data refresh so all meta data will be refreshed.

The second method uses a redirect to the system meta data screen showing how you can add in the additional parameters to force the type of meta data refresh you need.

Comments
  • If I use the CRM.RefreshMetadata() method I get the following sql error:

    Dec 19 2009 15:39:55.812 11828 7412 1 fselectsql,time,sql,errormsg 110 SELECT Capt_Code, Capt_Family, Capt_IntegrationId, Capt_ FROM vCustom_Captions WHERE  Capt_Family = N'Button' ORDER BY Capt_Family, Capt_Order, Capt_Code Invalid column name 'Capt_'

    This is with CRM6.2d.  Is there a fix available for this?