Wednesday, August 17, 2016

How to create Lookups on Dialog: SysTableLookup and registerOverrideMethod

We can create a lookup in dialog without hardcode the field object (Fld1_1_lookup) using the form control's registerOverride method.

SysTableLookup can be used in dialogs to create custom lookups.
control.registerOverrideMethod can be used to register the methods to override by an object.
Here is the example which shows basic usage of both. We will create a dialog and get a lookup of account numbers on a control.

Tuesday, August 2, 2016

How to deserialize xml into table from code

class JJK_XMLDeserializer
{
Common common;
str xmlStr;
Integer tableLevel;
}

public str deserialize()
{
XmlTextReader xmlTextReader; int level = 0;
str fieldName;
;

xmlTextReader = XmlTextReader::newXml(xmlStr, true);

while(xmlTextReader.read())
{
switch (xmlTextReader.NodeType())
{
case XmlNodeType::Element: // The node is an element.
//print ("<" + xmlTextReader.Name() + ">");
level++;
if ( level == tableLevel )
{
common.clear();
}
fieldName = xmlTextReader.name();
break;
case XmlNodeType::Text: //Display the text in each element.
//print (xmlTextReader.Value());
this.processRecord(common, fieldName, xmlTextReader.value());
break;
case XmlNodeType::EndElement: //Display the end of the element.
//print ("</" + xmlTextReader.Name() + ">");
level--;
if ( level==tableLevel-1 )
{
common.insert();
common.clear();
}
break;
}
}
return "";
}

public void processRecord(Common _common = common, str _fieldName = '', str _fieldValue = '')
{
DictTable dTable = new DictTable(_common.TableId);
DictField dField;
int i, fieldId;
str value;
;
// Loop through all the fields in the record
for (i=1; i<=dTable.fieldCnt(); i++)
{
// Get the fieldId from the field-count
fieldId = dTable.fieldCnt2Id(i);

// Find the DictField object that matches the fieldId
dField = dTable.fieldObject(fieldId);

// Skip system fields
if (dField.isSystem())
continue;

if ( dField.name()!=_fieldName )
{
continue;
}
// Convert values to string. I have just added
// a couple of conversion as an example.
// Use tableName.(fieldId) instead of fieldname
// to set the content to the field.

switch (dField.baseType())
{
case Types::Int64 :
_common.(fieldId) = str2int64(_fieldValue);
break;
case Types::Integer :
_common.(fieldId) = str2int(_fieldValue);
break;
default :
_common.(fieldId) = _fieldValue;
break;
}
return;
}
}

Test string:
'<xml >'
+'<JJK_XMLAttachment action="create">'
+'<RefRecId>555</RefRecId>'
+'<RefTableId>555</RefTableId>'
+'<XMLDocument>Test</XMLDocument>'
+'</JJK_XMLAttachment>'
+'<JJK_XMLAttachment action="create">'
+'<RefRecId>222</RefRecId>'
+'<RefTableId>222</RefTableId>'
+'<XMLDocument>Test222</XMLDocument>'
+'</JJK_XMLAttachment>'
+'</xml>';