Load JavaScript WebResource at runtime

Update... added Browser-agnosticity


function LoadWebResource(resource)
{
   var httpRequest = _createXMLHttpRequest();
   httpRequest.open("GET", Xrm.Page.context.getServerUrl() + "/webresources/" + resource, false);
   httpRequest.send(null);
   try {
      eval(httpRequest.responseText);
   }
   catch (e) {
      alert("Error loading " + resource + ":\n" + e.description);
   }
}

// Browser-agnostic factory function
function _createXMLHttpRequest()
{
   if (window.XMLHttpRequest) {
      return new XMLHttpRequest();
   } else if (window.ActiveXObject) {
      return new ActiveXObject('Microsoft.XMLHTTP')
   } else {
      _error("Could not create XMLHttpRequest on this browser");
      return null;
   }
} 


------



function LoadWebResource(resource) {    var orgName = Xrm.Page.context.getOrgUniqueName();    var httpRequest = new ActiveXObject("Msxml2.XMLHTTP");    httpRequest.open("GET", "/" + orgName + "/webresources/" + resource, false);    httpRequest.send(null); try {       eval(httpRequest.responseText); } catch (e) {       alert("Error loading " + resource + ":\n" + e.description);    } }
Advertisements

JQuery Mobile Web Client on SharePoint – The Source Code

After numerous requests of publishing the source code of my demo as showed before in JQuery Mobile Web Client on SharePoint enabled I have decided to do so.
You lucky bastards… from the goodness of my hart… and for the good of community… and for world peace.

Please be aware that the solution has not left the alpha stage.
Download the code here … SharePoint4Mobile… this is a .DOC file, cause WP didn’t allow me to upload an archive.
So …  rename the download from .DOC to .ZIP and you’ll be all set.

Things you wanna know:

  • It was developed against SharePoint 2007 in an BPOS environemnt… so you come across some BPOS specific tag in the ASPX  pages.
  • It is mainly JavaScript, cause of the BPOS SharePoint 2007 restrictions… you can make this work using .NET better and faster I’ll bet.
  • An important component I used was the 2008 SPAPI by Darren Johnstone (http://darrenjohnstone.net).

Good luck and feel free to let me know what the experiences were with this piece of code.
I’m allways open for feedback.

 

You may wonder why I stopped developing futher.
This has a fairly simple reason.

My goal was developing an App that enabled a user on at least iPhone or iPad to not just Open and Edit MS Office files… but Save modified files back to SharePoint.
This last feature … saving changed files back to SharePoint – is not possible with iPhone or iPad.
Read one of many articles stating what Apple had NOT done to to leverage SharePoint functionality with an iPhone or iPad.
http://blog.wortell.nl/jasper/the-ipad-and-sharepoint-%E2%80%93-what-can-and-can%E2%80%99t-you-do-%E2%80%93-part-1/

 

Pass a ListItemId to SharePoint workflow

In SharePoint Designer 2007 open the page where an action is needed.

Right click the control the wher you want to start the workflow from… click Form Actions.

Add Custom Action and click Settings and the Workflow Wizard will start.

Click Variables and add a variable called something like MyListItemId.

Finish the workflow and see that the code around your control will be updated somewhat like this:

<a href=”javascript: {ddwrt:GenFireServerEvent(‘__workflowStart={{FA532C23-6F80-4266-868D-1EBC219A7E11},New,{8F0B8599-4B45-421A-A4A2-9BD2817078DE},}’)}”>
//MyControl//
</a>

 

Here’s what you need to do to pass the variable MyListItemId

<a href=”javascript: {ddwrt:GenFireServerEvent(concat(‘__workflowStart={{FA532C23-6F80-4266-868D-1EBC219A7E11},New,{8F0B8599-4B45-421A-A4A2-9BD2817078DE},MyListItemId=’,@ID, ‘}’))}”>
//MyControl//
</a>

 

EASY AS PIE

Preview JavaScript files in Windows7 Explorer

For all you JS-hackers out there… here’s the way to make Windows7 to show a preview of a JavaScript file.
In the registry add a STRING value to the HKEY_CLASSES_ROOT\.js node called PerceivedType with the value text.
That’s all there’s to it.

Like this..!

 

Or make a registry file containing:

 

Windows Registry Editor Version 5.00

 

[HKEY_CLASSES_ROOT\.js]

“PerceivedType”=”text”

Copying Dynamics CRM form values to the clipboard

For multiple records MS CRM options like mail merge and Excel exports are mighty handy.
For single record data export the Clipboard is more the way to go.

If you need the name and address of a certain account or contact … you want that to be directly available… in your CTRL-V.
If you want to print using a label printer… perhaps.
Exporting it to Excel or starting the Mail Merge may be a bit much to do… you for one record.

Start using this option… an ISV button “Copy name and address to clipboard” executing a JavaScript copying certain values to the clipboard.

OnLoad

CopyToClipboard =

    function () {

        // Construct the string you want on the clipboard.

        var sClipBoard = crmForm.all.firstname.DataValue + ” ” + crmForm.all.lastname.DataValue + “\n” +

                       crmForm.all.address1_line1.DataValue + “\n” +

                       crmForm.all.address1_city.DataValue + “, ” + crmForm.all.address1_stateorprovince.DataValue + ” ” + crmForm.all.address1_postalcode.DataValue;

        // Use/Create a input area

        var oClipBoard = document.getElementById(“ClipBoard”);

        if (oClipBoard == null) {

           oClipBoard = document.createElement(“input”);

           oClipBoard.setAttribute(“id”, “ClipBoard”);

           oClipBoard.setAttribute(“type”, “hidden”);

            document.getElementById(“crmForm”).appendChild(oClipBoard);

            }

        // Put in the clipboard string

        oCopyArea.innerText = sClipBoard;

        // Now copy to the string clipboard

        var oCopyText = oCopyArea.createTextRange();

        oCopyText.execCommand(“Copy”);

        };

 

Make the function available as an ISV button:

 
 

        <Entity name=”contact” >

          <ToolBar>

            <Button JavaScript=” CopyToClipboard ();” Icon=”/_imgs/ico_16_132.gif” ValidForCreate=”1″ ValidForUpdate=”1″ AvailableOffline=”true”>

              <Titles>

                <Title LCID=”1033″ Text=” Copy name and address to clipboard ” />

              </Titles>

              <ToolTips>

                <ToolTip LCID=”1033″ Text=” Copy name and address to clipboard ” />

              </ToolTips>

            </Button>

          </ToolBar>

        </Entity>