Getting Started

VS 2010 - Download Script# 0.7.4.0 from http://projects.nikhilk.net/ScriptSharp
VS 2012 - Download Script# 0.7.5.1 from https://github.com/downloads/nikhilk/scriptsharp/ScriptSharp.0.7.5.1.vsix
  1. Download the latest release from http://sharpxrmpage.codeplex.com/releases
  2. Create a new Visual Studio 2010/2012 Script# Script Library Project
  3. Add a reference to the Xrm.Page import library you downloaded in step 2
  4. Add the following using statement "using Xrm;"
  5. That's it, start using it by using Page.* (eg: Page.Context.GetServerUrl())

Example
using System;
using System.Runtime.CompilerServices;
using System.Html;
using Xrm;

namespace Examples
{
    public class Tester
    {
        public static void OnSave(ExecutionContext context)
        {
            string value = Page.GetAttribute("mag_xyz").GetValue<string>();
            Script.Alert("value=" + value);

            context.GetEventArgs().PreventDefault();
        }
    }
}


Set lookup value
Lookup[] data = new Lookup[1];
data[0] = new Lookup();
data[0].EntityType = "account";
data[0].Name = "Hello Script#";
data[0].Id = "{guid-here}";

Page.GetAttribute("mag_lookupid").SetValue<Lookup[]>(data);


Get lookup value
Lookup[] lookup = Page.GetAttribute("mag_lookupid").GetValue<Lookup[]>();
Script.Alert(lookup[0].Name);


Get values
T value = Page.GetAttribute("mag_field").GetValue<T>();


Loop through controls
Page.Ui.Controls.ForEach(delegate(Control control, int index)
{
    if (control.GetControlType() != "iframe")
    {
        Xrm.Attribute attribute = control.GetAttribute();
        string value = attribute.GetValue<string>();

        Script.Alert("value is: " + value);
    }

    return true;
});

Last edited Aug 23, 2012 at 8:09 PM by gperera, version 8

Comments

Niwon Apr 8, 2012 at 11:17 PM 
Hey, Nice work !!
Is it possible to provide a example of how to create entities , or recieve them using this library?

csgexec Mar 13, 2012 at 8:11 PM 
Yes but I just realized I was trying to reference it through my parent class instead of a public function, etc. My bad...

gperera Mar 13, 2012 at 7:18 PM 
Did you add "using Xrm;" to the top of your class file?

csgexec Mar 13, 2012 at 2:41 PM 
Followed instructions - referenced dll but Intellisense apparently "unaware" of it. Entering any subclass of Page.* (anything after Page. such as Page.GetAttributes) is not recognized.