copy upload rules from one project/server to another one or add many rules from a text file

Hello,

I want to add upload rules on a new project that has to be setup on a new server. There are no upload rules existing at the moment.

1. Is there a way to export the upload rules from another server and then import on the the server?

2. If 1. is not possible, I want to add the rules from an excel or txt file instead of clicking 1000 times in the admin console.

I found Any Command line support Upload Rules ? - Dimensions CM User Discussions - OpenText Dimensions CM (microfocus.com) as answer from  

and tried this.

I copied this text block and added some line breaks:

importPackage(Packages.com.serena.dmclient.api)
try { //////////// Change these two up to your Product configuration:
var uploadEnvName = "Project Merge Tool;mrg";
var projName = "$GENERIC:TEST;mrg-123456"; // Replace "$24" with just "$" when you're taking this ID from Browser ///////////////////////////////////////////////////////////////
var db = defaultDatabase;
var env = db.uploadEnvironments.get(uploadEnvName);
if (env == null) throw ("Upload Environment '" uploadEnvName "' does not exist.");
var projs = env.projects;
var proj = projs.get(projName);
try { //Define a new inclusion rule variable
var fileNamePattern = "**/*.ext3\n**/*.ext4";
var dataFormat = "HTML";
var itemType = "SRC";
var designPart = "";
var seq = 2;
var exclusion = "**/Debug/*.*\n**/Release/*.*";
var incDetails =
new UploadInclusionDetails(fileNamePattern, dataFormat, itemType, designPart, exclusion); incDetails.seqNo = seq;
var incs = proj.inclusions; // Create a new upload inclusion rule inc = incs.add(incDetails);
print("Rule is added fine: " inc); } catch(e) { print(e) } } catch (e) { print(e) } finally { }

...into a file called AddRule.js and changed the var projName = "$GENERIC:QLARIUS;mrg-4213926" to "$GENERIC:TEST;mrg-123456" , the var uploadEnvName = "Project Merge Tool;mrg" seems to be the same in my project.

I ran the for a test the command dmpmcli -user admin -pass admPa$$word -dbname cm_typical -host DimCM-hostname -dsn dim15 -file C:\UploadRules\AddRule.js (adapted with my content , -host = server , -dbname = DB Name , -dsn = DB connection from the dimensions desktop login )

...but it just told me:

js: "C:\temp\AddRule.js", line 7: missing ) in parenthetical
js: if (env == null) throw ("Upload Environment '" uploadEnvName "' does not exist.");
js: ............................................................^
js: "C:\temp\AddRule.js", line 20: missing ) after argument list
js: print("Rule is added fine: " inc); } catch(e) { print(e) } } catch (e) { print(e) } finally { }
js: ................................^
js: "C:\temp\AddRule.js", line 1: Compilation produced 2 syntax errors.
js: Compilation produced 2 syntax errors.

I have no idea, what is wrong.

And even if this will work, I have no idea, how to add another 100 upload rules in this code. I think it would be better to have not all these variable definitions and instead put directly all needed info in one single command line? This Line I could duplicate with excel for every new upload rule - would this be possible?

Parents
  • Verified Answer

    Hello Andreas,

    I think that's Community migration has moved a post with some mistakes, removing end of lines and replacing some characters in the sample code for some reason.

    So, in the 7th and the 20th lines "+" characters  became missing (meaning to concatenate strings with variables into a single string. I.e.:

    throw ("Upload Environment '" + uploadEnvName + "' does not exist.");
    ...
    print("Rule is added fine: " + inc);

    I believe reading a file is quite possible from JavaScript, so knowing JS you'd turn that into a loop through read from file lines of rules and insert each into a necessary project.

    The same can be done using Dimensions CM Java API, if you prefer coding in Java instead of JavaScript.

    There is no Dimensions CM Command Line command to add Upload Rules, but actually once you make your JS mentioned above to insert a single rule, then you can call it passing parameters to it, so it serves as that "command". 

    https://admhelp.microfocus.com/dimensionscm/en/14.7/online_help/Content/InstallConfigure/ScriptingInterface/use-scripting-interface-shell.htm?Highlight=dmpmcli :

    dmpmcli ...
    [-file <script file> [<script arguments>]]

    However, doing everything inside of JS file (or Java code) will be much more faster approach, since it will avoid a reconnect on each JS invocation.

    --
    Alex Shevchenko
    Sr Development Manager
    Although I work for OpenText, I am speaking for myself and not for OpenText.
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button.

Reply
  • Verified Answer

    Hello Andreas,

    I think that's Community migration has moved a post with some mistakes, removing end of lines and replacing some characters in the sample code for some reason.

    So, in the 7th and the 20th lines "+" characters  became missing (meaning to concatenate strings with variables into a single string. I.e.:

    throw ("Upload Environment '" + uploadEnvName + "' does not exist.");
    ...
    print("Rule is added fine: " + inc);

    I believe reading a file is quite possible from JavaScript, so knowing JS you'd turn that into a loop through read from file lines of rules and insert each into a necessary project.

    The same can be done using Dimensions CM Java API, if you prefer coding in Java instead of JavaScript.

    There is no Dimensions CM Command Line command to add Upload Rules, but actually once you make your JS mentioned above to insert a single rule, then you can call it passing parameters to it, so it serves as that "command". 

    https://admhelp.microfocus.com/dimensionscm/en/14.7/online_help/Content/InstallConfigure/ScriptingInterface/use-scripting-interface-shell.htm?Highlight=dmpmcli :

    dmpmcli ...
    [-file <script file> [<script arguments>]]

    However, doing everything inside of JS file (or Java code) will be much more faster approach, since it will avoid a reconnect on each JS invocation.

    --
    Alex Shevchenko
    Sr Development Manager
    Although I work for OpenText, I am speaking for myself and not for OpenText.
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button.

Children
  • Thank you very much Alex!

    I modified the example now to have all variables in one line that I can duplicate for every new rule and it works.

    importPackage(Packages.com.serena.dmclient.api) 
    try { // Change these two up to your Product configuration: 
    	var uploadEnvName = "Project Merge Tool;mrg"; 
    	var projName = "$GENERIC:TEST;mrg-123456"; // Replace "$24" with just "$" when you're taking this ID from Browser //
    	var db = defaultDatabase; 
    	var env = db.uploadEnvironments.get(uploadEnvName); 
    	if (env == null) throw ("Upload Environment '" + uploadEnvName + "' does not exist."); 
    	var projs = env.projects; 
    	var proj = projs.get(projName); 
    	try { //Define a new inclusion rule variable 
    		var incDetails = new UploadInclusionDetails("**/*.ext3", "HTML", "ITEM", "", ""); incDetails.seqNo = 2; var incs = proj.inclusions; inc = incs.add(incDetails); print("Rule is added fine: " + inc ); 
    		var incDetails = new UploadInclusionDetails("**/*.ext4", "HTML", "ITEM", "", ""); incDetails.seqNo = 3; var incs = proj.inclusions; inc = incs.add(incDetails); print("Rule is added fine: " + inc ); 
    		} catch(e) { print(e) } 
    } catch (e) { print(e) } finally { }