Skip to main content
Aug 28, 2019 2:40 PM UTC
Question

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

@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?

6 replies

Aug 28, 2019 9:41 PM UTC

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-2Author
Aug 28, 2019 9:55 PM UTC

@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 🙂

Aug 28, 2019 10:00 PM UTC

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