none
ECMAScript Reference for Project Server RRS feed

  • Question

  • Hi,

    I'm attempting to interact with the JSGrid on the timesheet page in Project Server using Javascript. I want to evaluate some of the data as the users enter it and compare it to data I'm pulling from the PSI via AJAX, then alert the user accordingly.

    Unfortunately the reference contains nothing but function names, with little information on how to use them, the -debug.js files included with Project Server are thousands of lines long, and attempting to work out how to do it from these is proving very difficult.

    Any pointers or more detailed references would be greatly appreciated.
    Thursday, January 14, 2010 11:52 AM

Answers

  • Thanks for the post.  Bets way to do this is to tie into the remote text converter or use one of the grid built in delegates.  Below is an example i wrote  for the Project Timesheet that will mark a cell as errored if its greated than 8hrs of work are entered and also when coupled with a ribbon button allows you to enable/disable a particular row based on the admin line type.  This should get you started in how the grid overall works.  We are still working on documenation at the moment.  If you have more specific questions though ask away.  Hopefully this gets you started

    /// <reference name="MicrosoftAjax.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/Utility.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/WebMethodManager.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/shell.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/TimesheetSatellite.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/RemoteTextConv.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/ProjectFramework.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/GridSatellite.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/projectserverscripts.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/pagepropertymgr.debug.js"/>
    /// <reference path="~/_layouts/JsGrid.debug.js"/>
    
    var x;
    var prevDelegate;
    var togglePress;
    _spBodyOnLoadFunctionNames.push("Main");
    
    function Main() {
        x = new CustomizeTimesheetEntry();
        togglePress = false;
    }
    
    
    function CustomizeTimesheetEntry() {
        var _grid;
        //Prevent javascript errors if PJ or the AddGridSatellite function are not defined
        if (window.PJ == null || PJ.AddGridSatelliteInitializationNotifier == null) {
            return;
        }
           
        //Use the PJ.AddGridSatelliteInitializationNotifier function to get an instance of the satellite
        PJ.AddGridSatelliteInitializationNotifier
        (
        function (satellite) {
            if (PJ.TimesheetSatellite != null) {
                _grid = satellite.GetJsGridControlInstance();
                prevDelegate = _grid.GetDelegate(SP.JsGrid.DelegateType.GetRecordEditMode);
                _grid.SetDelegate(SP.JsGrid.DelegateType.GetRecordEditMode, SetRecordEditMode);
    
                var existingValidationFunc = PJ.RemoteTextConv.GetPostprocessor(PJ.ConversionType.Work);
                PJ.RemoteTextConv.RegisterPostprocessor(PJ.ConversionType.Work, CustomPostProcessor);
    
                function CustomPostProcessor(convType, fieldKey, newValue, bIsLocalized, formatType, textConvConfigs, result) {
                    if (existingValidationFunc != null) {
                        result = existingValidationFunc(convType, fieldKey, newValue, bIsLocalized, formatType, textConvConfigs, result);
                    }
                    if (result.isValid){
                        if (result.dataValue > 480000) {
                            result.isValid = false;
                            result.errorMsg = "You are not allowed to enter more than 8 hours of work";
                        }
                    }
                    return result;
                }
            }
    
        }
        );
    
        function SetRecordEditMode(record) {
            if (record.GetDataValue("TS_LINE_CLASS_NAME") == "Sick time" && togglePress) {
                //TS_LINE_CLASS_TYPE => http://msdn.microsoft.com/en-us/library/websvcadmin.timesheetlineclassdataset.lineclassesrow.ts_line_class_name(office.14).aspx
                return SP.JsGrid.EditMode.ReadOnly;
            }
            else {
                prevDelegate;
            }
        }
    
        this.DisableGridRows = function () {
            if (togglePress) {
                togglePress = false;
            }
            else {
                togglePress = true;
            }
            _grid.RefreshAllRows();
        }
    }
    
    Friday, January 15, 2010 6:54 AM
    Moderator

All replies

  • Thanks for the post.  Bets way to do this is to tie into the remote text converter or use one of the grid built in delegates.  Below is an example i wrote  for the Project Timesheet that will mark a cell as errored if its greated than 8hrs of work are entered and also when coupled with a ribbon button allows you to enable/disable a particular row based on the admin line type.  This should get you started in how the grid overall works.  We are still working on documenation at the moment.  If you have more specific questions though ask away.  Hopefully this gets you started

    /// <reference name="MicrosoftAjax.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/Utility.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/WebMethodManager.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/shell.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/TimesheetSatellite.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/RemoteTextConv.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/ProjectFramework.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/GridSatellite.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/projectserverscripts.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/pagepropertymgr.debug.js"/>
    /// <reference path="~/_layouts/JsGrid.debug.js"/>
    
    var x;
    var prevDelegate;
    var togglePress;
    _spBodyOnLoadFunctionNames.push("Main");
    
    function Main() {
        x = new CustomizeTimesheetEntry();
        togglePress = false;
    }
    
    
    function CustomizeTimesheetEntry() {
        var _grid;
        //Prevent javascript errors if PJ or the AddGridSatellite function are not defined
        if (window.PJ == null || PJ.AddGridSatelliteInitializationNotifier == null) {
            return;
        }
           
        //Use the PJ.AddGridSatelliteInitializationNotifier function to get an instance of the satellite
        PJ.AddGridSatelliteInitializationNotifier
        (
        function (satellite) {
            if (PJ.TimesheetSatellite != null) {
                _grid = satellite.GetJsGridControlInstance();
                prevDelegate = _grid.GetDelegate(SP.JsGrid.DelegateType.GetRecordEditMode);
                _grid.SetDelegate(SP.JsGrid.DelegateType.GetRecordEditMode, SetRecordEditMode);
    
                var existingValidationFunc = PJ.RemoteTextConv.GetPostprocessor(PJ.ConversionType.Work);
                PJ.RemoteTextConv.RegisterPostprocessor(PJ.ConversionType.Work, CustomPostProcessor);
    
                function CustomPostProcessor(convType, fieldKey, newValue, bIsLocalized, formatType, textConvConfigs, result) {
                    if (existingValidationFunc != null) {
                        result = existingValidationFunc(convType, fieldKey, newValue, bIsLocalized, formatType, textConvConfigs, result);
                    }
                    if (result.isValid){
                        if (result.dataValue > 480000) {
                            result.isValid = false;
                            result.errorMsg = "You are not allowed to enter more than 8 hours of work";
                        }
                    }
                    return result;
                }
            }
    
        }
        );
    
        function SetRecordEditMode(record) {
            if (record.GetDataValue("TS_LINE_CLASS_NAME") == "Sick time" && togglePress) {
                //TS_LINE_CLASS_TYPE => http://msdn.microsoft.com/en-us/library/websvcadmin.timesheetlineclassdataset.lineclassesrow.ts_line_class_name(office.14).aspx
                return SP.JsGrid.EditMode.ReadOnly;
            }
            else {
                prevDelegate;
            }
        }
    
        this.DisableGridRows = function () {
            if (togglePress) {
                togglePress = false;
            }
            else {
                togglePress = true;
            }
            _grid.RefreshAllRows();
        }
    }
    
    Friday, January 15, 2010 6:54 AM
    Moderator
  • Thanks Patrick, that's great.

    I'll be working on this on Monday, and I'll let you know how I get on!

    Regards
    Chris
    Friday, January 15, 2010 2:29 PM
  • I receive Jscript runtime error "Object does't support this property or method" on "_grid = satellite.GetJsGridControlInstance();"?

    Monday, October 18, 2010 12:01 PM
  • Do not forget to put the following lines of code just before the call to GetJsGridControlInstance()  
    Apparently this is a known issue.

    /*** Satellite override: Project code should pass in "sat" instead of "this" ***/

     

     

    satellite = PJ._NotifySatelliteInitComplete.arguments[0];
    _satellite = satellite;
    /***End Satellite override***/

    Wednesday, October 20, 2010 7:48 AM
  • hello Patrick:

    in the place of

      if (result.dataValue > 480000) {

                result.isValid = false;
                result.errorMsg = "You are not allowed to enter more than 8 hours of work";
              }

    I would like to do is as shown below. 

    if (result.dataValue > 480000) {

    				var result = showSPDialog(url);
    			result.isValid = false;
    			 result.errorMsg = "Invalid value entered";
              }

    Please can you help me with getting the value from the window. I am not able to get the value from the dialog page or the NotifyCallBack , please help!

     function showSPDialog(pageToLoad) {
        var options = {
          url: pageToLoad,
          title: 'Work Reference Validation Page',
          showClose: true,
          width: 700,
          height: 250,
          allowMaximize: false,
          showOK: true
          ,dialogReturnValueCallback: NotifyCallBack
        };
    
        SP.UI.ModalDialog.showModalDialog(options);
    }
    
       
        function NotifyCallBack(dialogResult, returnValue) {    
        if (returnValue != null) {
          SP.UI.Notify.addNotification(returnValue);
        }
      }


     

    Simi
    Wednesday, July 20, 2011 7:20 AM
  • Hello,

    I have a question about the the above (and similar code excerpts that use CustomPostProcessor):

    (result.dataValue > 480000) seems to be working either for individual cells or for their combination. For example, I can generate an error message for a task where I put 9h of actual work, or for a combination of tasks (6h and 4h). I don't understand how this actually works, i.e. by using a single if.

    My requirement is to check if actual work > 8h either for a task or for a number of tasks on the same day. I get this working with the above code, but by using a single if which is a bit weird. Result.DataValue seems to sum up individual entries, e.g. for 2 tasks I put actual work 6h and 4h respectively. Result.dataValue gets 6h at first, then 4h and then it calculates 10h and generates the error message.

    I would expect at least 2 ifs, one for a task's actual work and another for the total actual work per day...

     

    Can you please explain or am I doing something wrong? Here is the code I am testing:

     

    if ((fieldKey == "TPD_col0a") || (fieldKey == "TPD_col1a") || (fieldKey == "TPD_col2a") || (fieldKey == "TPD_col3a") || (fieldKey == "TPD_col4a") || (fieldKey == "TPD_col5a") || (fieldKey == "TPD_col6a")) {

    if (result.dataValue > 480000) {

        _errorMsg = "You cannot enter more than 8h of actual work per day.";

         result.isValid = false;

        result.errorMsg = _errorMsg;

    }

    }

     

     

    Monday, July 25, 2011 8:19 AM