What is the Function or Method to be used in Macro to apply the Template for the models .
We have used Designer.applyTemplate() function and passed the Guid of the template but it did not work.
Hi,
You must use the construction below.
Succes,
Edwin
================================================
var oModels = Context.getSelectedModels();
var oDB = Context.getLoginInfo(oModels[0]).getDatabase();
var oTempls = Designer.getAvailableTemplates(oDB);
for(i=0;i<oTempls.length;i++) {
if (oTempls[i].getGUID()=="f94133b0-3300-11de-34a6-0015587d97aa") {
var oTempl = oTempls[i];
break;
}
}
if(oTempl!=null){
for(i=0;i<oModels.length;i++) {
Designer.applyTemplate(oModels[i], oTempl);
}
}
Hello Edwin,
My requiremnt is to create Datatypemodels dynamically.I have a report that create the DATA_Type, but the name is not getting disaplyed on DATA_TYPE element in the model viewer.
My code is as beow
var objdef = oGroup.GetOrCreateObjDef( g_datatype_type,2,g_objdef_name,g_nLoc);
var attr1def = oGroup.GetOrCreateObjDef( g_attribute_type,2,g_attrdef_name,g_nLoc);
var oModel = arCreateModel(g_mt_datatype_model,oGroup,gdt,g_nLoc );
if( (oModel != null) && (oModel.IsValid()) )
{ //APply template
var template = "_SAP: Data Type Model";
Designer.applyTemplate(oModel,template); }
But Here i am getting an error like 'Designer is not defined'.
So i tried ur code suggestion as below...
var objdef = oGroup.GetOrCreateObjDef( g_datatype_type,2,g_objdef_name,g_nLoc);
var attr1def = oGroup.GetOrCreateObjDef( g_attribute_type,2,g_attrdef_name,g_nLoc);
var oModel = arCreateModel(g_mt_datatype_model,oGroup,gdt,g_nLoc );
if( (oModel != null) && (oModel.IsValid()) )
{ //APply template
var oDB = Context.getLoginInfo( Context.getSelectedDatabases()[0] ).getServerName();
var oTempls = Designer.getAvailableTemplates(oDB);
Here again i am gettin error like Cannot find function getLoginInfo in object COntext@4563bba4
Regards,
Linda
Hi Linda,
You are building a script for a report and not for a macro. The solution i described was for the macro object model. In the report object model you should use:
var bTemplateAssigned = oModel.setTemplate("7ca16360-6684-11dc-2b8d-000f20fcb6a9") ;
If bTemplateAssigned is true, then the template is assigned correctly.
Succes,
Edwin
Hi Linda,
Forgot one small thing. The second parm in method setTemplate(String guidTemplate, boolean bApplyTemplate ) needs to be set to true. sorry for that.
var bTemplateAssigned = oModel.setTemplate("7ca16360-6684-11dc-2b8d-000f20fcb6a9", true) ;
Best regards,
Edwin
Hi Linda,
I created a little script to apply the template. It looks like below, and it works fine for me.
var nLocale = Context.getSelectedLanguage(); main(); function main() { var oModels = ArisData.getSelectedModels(); for (var i=0;i<oModels.length;i++) { var bTemplateAssigned = oModels[i].setTemplate("fedac4a0-2f64-11e0-46d1-0022fbbb78d0", true) } }
Best regards,
Edwin
I want to set template to an object occurence and not whole model. can I do this with script ?