Skip to content

Instantly share code, notes, and snippets.

@AshV
Last active November 25, 2016 19:07
Show Gist options
  • Save AshV/3f46db308b56611447f1b84a7810cae2 to your computer and use it in GitHub Desktop.
Save AshV/3f46db308b56611447f1b84a7810cae2 to your computer and use it in GitHub Desktop.
FetchXML to C# & JS Formatter
<div align="center">
<h1>FetchXML Formatter Online</h1>
<textarea id="src" placeholder="Paste your fetchXML here." wrap="off"></textarea>
<textarea id="cs" placeholder="C# formatted code appears here." wrap="off"></textarea>
<textarea id="js" placeholder="JavaScript formatted code appears here." wrap="off"></textarea>
<br/> <br/>
<a href="https://arunpotti.wordpress.com/2014/11/15/fetchxml-formatter-tool/comment-page-1/" target="_blank">Inspired from Arun's CRM Blog</a>
<br/>
<a href="http://AshishVishwakarma.com/" target="_blank">Powered by AshV</a>
</div>
var srcTxt = document.querySelector("#src");
var csTxt = document.querySelector("#cs");
var jsTxt = document.querySelector("#js");
srcTxt.onkeyup = function() {
var srcValue = new String();
srcTxt.value.trim().replace(/"/g, "'").split('\n').forEach(function(line) {
if (line.length > 0) {
if (line[0] == '+')
{}
else {
if (line[0] == '-') {
srcValue += line.substring(1, line.length)+"\n";
} else
srcValue += line + "\n";
format(srcValue);
}
}
});
};
var format = function(srcValue) {
csTxt.value = ('@"' + srcValue.substring(0, srcValue.length - 1) + '"');
var jstxt = new String();
srcValue.split('\n').forEach(function(line) {
jstxt += '"' + line + '"+\n';
});
jsTxt.value = jstxt.substring(0, jstxt.length - 6);
};
html,
body,
div {
height: 100%;
}
textarea {
height: 70%;
width: 30%
}
h1,
a {
color: gray;
}
a {
text-decoration: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment