Skip to main content
1-Visitor
August 28, 2019
Question

Thingworx and Visual Studio Code with any Source Control, CI / CD

  • August 28, 2019
  • 1 reply
  • 3284 views

@htran-21 This is great!  I've been searching around to try to figure out how you're extracting the JS from the XML, but not having much luck.  Could you please share your process to extract and create the corresponding .js/.sql files?

1 reply

15-Moonstone
August 28, 2019

Hi @wposner-2 

 

Here is the code that i use to extract JS code and SQL code from the XML

 

docNew.XPathSelectElements($"//ThingShape/ServiceImplementations/ServiceImplementation").ForEach(codeElement =>
{
	var handler = codeElement.Attribute("handlerName").Value;
	var name = codeElement.Attribute("name").Value;
	if (string.Equals("Script", handler))
	{
		// Javascript
		codeElement.XPathSelectElement("*//Rows/Row/code").WriteJS($"{entityFolderPath}/{name}.js", merge);
	}
	else
	{
		// SQLCommand, SQLQuery
		codeElement.XPathSelectElement("*//Rows/Row/sql").WriteSQL($"{entityFolderPath}/{name}.sql", merge);
	}
});

 

You may need to extract mashup code, so that you would be able to track/merge UI changes 

// Mashups
docNew.XPathSelectElements($"//{entityCollection}/{entityType}/Things").Where(_ => _.HasElements)
.ForEach(codeElement => codeElement.WriteXML($"{entityGroupFolderPath}/{entityName}.xml", merge)); docNew.XPathSelectElements($"//{entityCollection}/{entityType}/mashupContent") .ForEach(codeElement => codeElement.WriteJSON($"{entityGroupFolderPath}/{entityName}.json", merge));

 

Hope this helps!

 

My Bests,

Hung Tran

wposner-21-VisitorAuthor
1-Visitor
August 28, 2019

@htran-21 Thank you!  One final question.  How are you merging your JS/SQL back in to to the XML so that it can be re-imported to TWX?  I'm really hoping this is not a copy/paste operation 🙂

15-Moonstone
August 28, 2019

Hi @wposner-2 

 

No, everything is automatic, just perform merge task, and the final XML would be merged with the latest local/remote changes

 

Screenshot_1.png

 

My Bests,

Hung Tran