AnsweredAssumed Answered

REST API how to update date/datetime fields

Question asked by KenTseG4S on Jun 17, 2015
Latest reply on Jun 18, 2015 by KenTseG4S

Hi I'm trying to develop a mobile friendly web front end for Service Desk using the RESTAPI and the mobiledemo example provided by CA.

 

For the most part it's pretty straight forward except for dealing with date/datetime fields.

 

display is straight forward, the issue is edit/update.  I'm trying to tie the edit field to a datepicker using a jquery datepicker library.

 

However, I thought the default sdmindetail.js covered how to handle dates however alas no:

 

   // detect date values and apply the treatment

        if ( isDateType(attrName) )

        {

            // No date selector support as yet so dates cannot be updated

            continue;

        }

 

 

Can someone tell me how to update this?  With the service management mobile app, which can handle dates, this function's code should be available.

 

Whole sdmindetail.js below:

 

 

// update the object (ticket) based on changes captured in the deltaObject

// creates JSON object representing changes made and performs update via ajax call

function doUpdate()

{

    var updateObject = "{ \"" + PACKAGENAME + "\" : { ";

    var updatesReady = false;

    // build JSON object for update

    for ( attrName in deltaData)

    {

        var valueID = "#ef_" + attrName;

        var hiddenID = "#h_ef_" + attrName;

        if ( document.getElementById(valueID.substring(1)) == null)

            continue;

 

        // detect date values and apply the treatment

        if ( isDateType(attrName) )

        {

            // No date selector support as yet so dates cannot be updated

            continue;

        }

 

        // determine whether this is the first updated attribute detected

        if ( updatesReady )

            updateObject += ', ';

 

        updateObject += '\"' + attrName + '\" : ';

 

        // detect SREL  values and apply the treatment

        if ( document.getElementById(valueID.substring(1)).tagName.toUpperCase() == 'SELECT' ||

                document.getElementById(hiddenID.substring(1)) != null)

        {

            updateObject += '{ \"@REL_ATTR\" : ' + '\"'  + deltaData[attrName] + '\" } ';

            updatesReady = true;

            continue;

        }

 

        // Not an SREL so just specify literal values (no QRELs, BRELs, LRELs)

        updateObject += '\"'  + deltaData[attrName] + '\" ';

        updatesReady = true;

    }

    var query = getRestUrl() + '/' + PACKAGENAME + '/' + urlParms['ID'];

 

    // if any updates were prepared, perform update via ajax

    if ( updatesReady)

    {

        updateObject += "} }";

        makeAjaxPutCall2(query, getAccessKey(), updateObject, 'json', processJSONforTransition, getObjAttrs(getAttrs(getUIType())));

    }

    else

    {

        // No updates were done, just redirect to view screen

        makeAjaxGetCall(query, getAccessKey(), getObjAttrs(getAttrs(getUIType())), "json", processJSON);

    }

}

Outcomes