Skip to main content

Development

eScript Property Set Printing Tool

During script debugging, for example, when developing a Virtual Business Component, it is useful to be able to print out the contents of a property set. This blog introduce an eScript code that can be added to a business service to print out the contents of a property set.

 

 The eScript code will handle multiple level property sets. It is not limited to one or two layers of child property sets; rather, it is recursive and handles any depth of child property sets.

 

The listing also shows the child depth so you can see at a glance how deep in the hierarchy you are. The indent amount is configurable, so for property sets with several children you can choose a smaller indent.

 

The script provided writes out to a text file, but all the printed output is written through the LogMe() routine so it is easy to redirect it if required.

 

To add the code to a Business Service, follow these steps:

  • After the new functions appear, there will be a few lines of script code remaining in the General Declarations Section. You can make the following optional changes:

 

    1. Modify the output filename assigned to OutPutFileName if you wish to write to a different file. Remember that in eScript a backslash must be escaped, so a path name like C:\TEMP\LOGS\output.txt becomes C:\\TEMP\\LOGS\\output.txt.

 

    1. Change the indent level. It is two spaces by default.

 

  • Now when you want to print out the values in a property set, simply call it like this:

 

DumpPropSet(MyPropertySet);

eScript Code

 

// Add to General Declarations section

 

// Change this to the file and pathname you want the report to appear in.

var OutPutFileName = ‘C:\\PropertySet_Dump.txt’;

 

var IndentAmount = 2; // Indent child prop sets listing this many spaces

                     // to the right for each level down.

var PSDepth = 0; // How deep in the property set tree, what level

 

 

// Add to General Declarations section

 

function LogMe(LogThis)

{

  // Writes a line out to a text file. All printed output is routed

  // through this routine, so add HTML or popup writes here to redirect

  // the printed output.

 

  var MyFile = Clib.fopen(OutPutFileName, ‘at’);

  var sTime = Clib.ctime(Clib.time());

  sTime = sTime.replace(‘\n’,’ ‘); // Remove trailing Newline.

  Clib.fputs(sTime + ‘: ‘ + LogThis + ‘\n’, MyFile);

  Clib.fclose(MyFile);

}

 

function DumpPropSet(Inputs)

{

// Print out the contents of a property set.

 

PSDepth++; // We have just dived down a level

 

var InpValue;

var InpType;

var InpChildCount;

var inprop;

var inpropval;

var inpropcnt;

var BlankLine = ‘ ‘;

 

// Build a string to indent the Listing.

 

var IndentSpaces = ”; // Number of spaces to indent to

for (var SpaceCount = 0; SpaceCount < IndentAmount * PSDepth; SpaceCount++)

  {

  IndentSpaces = IndentSpaces + ‘ ‘;

  }

var IndentLevel = ToString(PSDepth);

if (PSDepth < 10)

  {IndentLevel = ‘0’ + IndentLevel;}

 

// Indent by a number of indents, then level number as nn, then two spaces

var Indent = IndentSpaces + IndentLevel + ‘  ‘;

 

 

LogMe(BlankLine);

LogMe(BlankLine);

LogMe(Indent + ‘—- Starting a new property set —-‘);

LogMe(BlankLine);

 

 

// Now do main value and type

 

InpValue = Inputs.GetValue();

InpType  = Inputs.GetType();

 

InpChildCount = Inputs.GetChildCount();

LogMe(Indent + ‘Value is …….. : “‘ + InpValue + ‘”‘);

LogMe(Indent + ‘Type is  …….. : “‘ + InpType + ‘”‘);

LogMe(Indent + ‘Child count ….. : ‘ + ToString(InpChildCount));

 

// Dump the properties of this property set

 

var PropCounter = 0;

inprop = Inputs.GetFirstProperty();

while (inprop != “”)

  {

  PropCounter++;

  inpropval = Inputs.GetProperty(inprop);

 

  LogMe(BlankLine);

  var PropCountStr = ToString(PropCounter);

  if (PropCounter < 10)

    { PropCountStr = ‘0’ + PropCountStr; }

  LogMe(Indent + ‘Property ‘ + PropCountStr + ‘  name : “‘ + inprop + ‘”‘);

  LogMe(Indent + ‘Property ‘ + PropCountStr + ‘ value : “‘ + inpropval + ‘”‘);

 

  inprop = Inputs.GetNextProperty();

  }

 

// Dump the children of this PropertySet

 

if (InpChildCount == 0)

  {

  LogMe(BlankLine);

  LogMe(Indent + ‘(No children exist below this property set.)’);

  }

else 

  {

  for (var ChildNumber = 0; ChildNumber < InpChildCount; ChildNumber++)

    {

    LogMe(BlankLine);

    LogMe(Indent + ‘Child Property Set ‘ + ToNumber(ChildNumber + 1) + ‘ of ‘ + ToNumber(InpChildCount) + ‘ follows below.’);

    LogMe(Indent + ‘This child is on level ‘ + ToNumber(PSDepth));

 

    // Recursive call for children, grandchildren, etc.

    DumpPropSet(Inputs.GetChild(ChildNumber));

    }

  }

 

PSDepth–; // We are about to pop up a level

}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us
TwitterLinkedinFacebookYoutubeInstagram