Script# (ScriptSharp) delete statement

I've been using Script# very succesfully for sometime now to generate CRM2011 Javascripts (you can get a version of the Xrm library for Script# at

I problem I encounted recently was where I needed to issue a delete statement. E.g.

delete xmlDoc;

There is only Type.DeleteField support in Script# which allows deleting of a field on an object, but there is no way of outputing a simple local scope delete statement.

I orignally used:

Script.Literal("delete xmlDoc");

This worked fine for debug scripts, however when using the release scripts that are minified, of course the variable xmlDoc is output as something like $1_0 and so the literal statement fails.

After some research I found that the following statement works:

Script.Literal("delete {0}",xmlDoc);

Hope this helps.

Comments are closed