Updating a Date Column in SP2010 using Javascript in WP

Hi,
I know that Today() doesn't work in SP. But seeing all the various JS codes to highlight rows etc is rather cumbersome, especially if you have several operations that you may want to run based on Today().
In my list, I have a column which is hidden from public view, 'thisDate'. This column is set to Date Only and with each new item that is added, it loads today's date. That's fine at item creation; but what I want to do is use JS to
update all fields in thisDate column with today's date whenever the list is first loaded on any new day.
<script type="text/javascript" language="javascript">
var tDate = null;
allItems = null;
ExecuteOrDelayUntilScriptLoaded(UpdateList, 'sp.js'); //this is necessary to ensure the library is loaded before function triggered
function DateThis(){
tDate = new Date().toJSON();
tDate.format("m/dd/yy");
return tDate;
function UpdateList(){
var tContext = new SP.ClientContext.get_current();
var tSite = tContext.get_site();
var tWeb = tSite.get_rootWeb();
var tList = tWeb.get_lists().getByTitle('TeamDUCOM LNO Travel');
var tQuery = SP.CamlQuery.createAllItemsQuery();
this.allItems = tList.getItems(tQuery);
tContext.load(allItems, 'Include(thisDate)');
tContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySuccess), Function.createDelegate(this, this.onQueryFailed));
function onQuerySuccess(){
var listEnum = allItems.getEnumerator();
var todaysDate = DateThis();
while(listEnum.moveNext()){
var currentItem = listEnum.get_current();
var origDate = currentItem.get_item('thisDate');
currentItem.set_item('thisDate',todaysDate);
currentItem.update();
tContext.executeQueryAsync(Function.createDelegate(this, this.ListItemsUpdateSuccess), Function.createDelegate(this, this.ListItemsUpdateFailed));
function onQueryFailed (){
alert('Query List Failed ');
function ListItemsUpdateSuccess(){
alert('Success ');
function ListItemsUpdateFailed(){
alert('Update List Failed ');
</script>
Right now, I get an 'onQueryFailed' alert saying the Query list failed.  Also in the watch windo, I get null for 'tDate and 'todaysDate' is undefined.
Once I can get this to work, it is my intention to add an extra line or two to compare variables
origDate with todaysDate. If they match, skip and go to next.  I think this would reduce updates and minimze the List sending out email alerts (most of my users use Alerts to be notified of changes to the list. (Bonus
would be being able to suspend any alert triggers at update, but I don't believe that's possible, or?)
After all the debugging, I also intend to comment out the alerts within the code, since no one needs to see that.
Ideally, this code would be reuseable on any list that needs countdowns, traffic lights, colorcoding etc, or even calcaulated columns using
thisDate data in lieu of the nonexistent Today()
function. And, as mentioned above, the list only needs to be updated once for the 1st person to open the list on any given day.
TIA
AH-C

Victoria,
That didn't work for me. When I stripped out the script tags fro the file and placed it around the script url, I kept getting an error message within the webpart while in page edit view: "Cannot retrieve the URL specified in the Content Link
property. For more assistance, contact your site administrator."
I tried both your suggested change and the older script every which way - before the list, after the list, hidden and not. I then focused more on the IE 9's F12 developer tool and watched as it stepped thru the code. Everything was fine with the variables
(each object loaded in the Locals view) until it came time to call the executeQueryAsync.
I even traced down the stack and confirming the arguments. But a thot kept bugging me about "get_rootweb". i had seen other examples where it was "get_web" instead. When I went back to search Bing, I came across an example where the coder
just cut to the chase, bypassing varibles (in my case, dropping 'tSite' & 'tWeb'), so my trimmed code snippet now looks like this:
var tContext = SP.ClientContext.get_current();
var tList = tContext.get_web().get_lists().getByTitle('MyList Name');
var tQuery = SP.CamlQuery.createAllItemsQuery();
this.everyItem = tList.getItems(tQuery);
Prior to that, I also changed the var 'allItems', because I wondered if that was causing conflicts, case-sensitivity notwithstanding, since my default list view was 'AllItems.aspx'
Anyway, it now works regardless of CEWP positioning/hidden status (using only the reference to JS file in SiteAssets and using the script tags within the js file, not the CWEP link) -- typically, I make such CWEPs (ie EasyTabs) hidden and at the bottom of
the page, after the list and it works just fine.
I'm going to mark this thread as answered. But before I do that, I'll work out the one piece I need to add for the code to do nothing to a particular item if 'todaysDate' matches 'origDate' then post the entire code as the solution.
Thanks again.
Best regards,
AH-C
PS, I got a deluge of email alerts telling me that the list was updated. I anticipated that and will be looking for code to stop that if possible.  But with the test for matching dates, at least I can limit the deluge of emails to once a day by whomever
is 1st to check the list that day (my alert is configured for instant alerting whenever a change has been made and I'd prefer to keep it that way, unless there's no workaround.

Similar Messages

  • How to update the data in sqlserver table using procedure in biztalkserver

    Hi,
    Please can any one answer this below question
    how to update the data in sqlserver table using procedure in biztalkserver
    while am using executescalar,typedprocedure getting some warning
    Warning:The adapter failed to transmit message going to send port "SendtoSql1" with URL "mssql://nal126//MU_Stage2?". It will be retransmitted after the retry interval specified for this Send Port. Details
    Please send me asap....
    Thanks...

    Hi Messip,
    A detailed error would have helped us to answer you more appropriately but
    You can follow the post which has step by step instructions, to understand how to use Stored Procedure:
    http://tech-findings.blogspot.in/2013/07/insert-records-in-sql-server-using-wcf.html
    Maheshkumar
    S Tiwari|User
    Page|Blog|BizTalk
    2013: Inserting RawXML (Whole Incoming XML Message) in SQL database

  • Can we update the data of ztable by using the BAPI FM

    Hi Experts,
    Can we update the data of ztable by using BAPI FM  'BAPI_CUSTOMERCONTRACT_CHANGE'.
    Can anyone help this issue.
    regs
    rams

    Hi Ramesh,
    After the BAPI 'BAPI_CUSTOMERCONTRACT_CHANGE' is called, check the return message and use UPDATE <DBTABLE_NAME> command to update the ZTABLE.
    Use COMMIT WORK after the call. If the BAPI is standard BAPI and not a customized BAPI, then it wont update Z Table direclty. You need to build the logic in program to update Z Table.
    Best regards,
    Prashant
    PS : Please reward all helpful answers

  • Update External data Column in share point2010 list

    Hi all,
    i have list and i am using External data column (From BCS).
    I am trying to update the external data field value. its updating and showing in view correctly but when i try to edit its showing old value only.
    Ex: I have a external data with field values ( test1,test2,test3,... so on)
    in the list i have a value test1, i am trying to update with test2..its updating in display and view but when i am trying edit its showing default still test1..

    Hi,
    The following articles for your reference:
    SharePoint 2010 BCS Field - Setting the field/column
    http://thealbuquerqueleftturn.blogspot.de/2011/12/sharepoint-2010-bcs-field-setting.html?m=1
    Programmatically Setting BCS Fields in SharePoint Custom Lists Client-Side through Web Services / SOAP
    http://blog.avanade.com/asg-collaboration-services/other/programmatically-setting-bcs-fields-sharepoint-custom-lists-client-side-web-services-soap/
    SharePoint 2013 – Update an External Data field using PowerShell
    http://veenstra.xyz/2014/06/03/sharepoint-2013-update-an-external-data-field-using-powershell/
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Updating the date column in oracle databse

    hi,
    iam having date column called applicationdate in my oracle database.
    i will update this column by jsp..
    when user enter the date value he clicks update then after that iam doing following things.
    String d = (String)req.getParamter("appdate");
    ex:7/7/2005
    preparedStatement.setString(1,d);
    if i execute this statement iam getting error not a valid month .bcos in my table its long date type..so how can i convert this d value t long date type and update using seDate() method..are with setString()..
    regards,

            String d = (String)req.getParamter("appdate");
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            java.util.Date date = sdf.parse(d);
            java.sql.Date sqlDate = new java.sql.Date(date.getTime());So you got a sql.Date and u canset this on the prepared statement
      ps.setDate(1, sqlDate);Watch out for the simpledateformat.. and specify the correct date format you are using...
    hope that helps

  • Update a date column

    Hello hello,
    I just want to update a column with a specific date.
    update table set date = ...
    I almost tried everything. Also to_char and to-date and I always get the following error Message:
    ORA-01747: invalid user.table.column, table.column, or column specification
    The table and column names are correct. It must have something to do with the format of the date or the code itself is principle wrong.
    regards phil

    Error: ORA-01747: invalid user.table.column, table.column, or columns specification
    Cause: You tried to reference a column name, but the column name used is a reserved word in Oracle.
    Solution:
    1)Try redefining your table so that none of your column names are reserved words.
    2)Try enclosing the reserved word in double quotes.
    Since you have used reserved words in oracle as column names, you get these error messages.
    Eg)
    UPDATE suppliers
    SET Integer = 10000;
    the above should give you an error message 1747. The correct way is as below:
    UPDATE suppliers
    SET "Integer" = 10000;

  • Update of date column keeping HH:MM:SS

    I am using the query below to update another parition but I am loosing time asssociated with
    the data. Can somebody show me how to keep the time and only modify YYYYMMDD part of
    the date
    update xxx.tab1 set create_date='20110522' where
    create_date >= to_date('2011/01/14', 'yyyy/mm/dd') and
    create_date < to_date('2011/01/15', 'yyyy/mm/dd');

    example
    update xxx.tab1
    set create_date=to_date('20110522','YYYYMMDD') + (create_date - trunc(create_date))
    where create_date >= to_date('2011/01/14', 'yyyy/mm/dd')
    and create_date < to_date('2011/01/15', 'yyyy/mm/dd');This adds a number value to your date. This number value happens to be the time portion of the create_date column.

  • Query To update a date column with a date of my interest

    All,
    How to update a column in a table which is in date format with a date of my interest??
    Pls suggest.

    Please detail :
    1. what exactly you are trying to do
    2. what exactly you have done
    Nicolas.

  • Conditional validation of date and text fields using javascript

    How can we validate text and date field in sharepoint newform based on a check box.
    i have used validation settings but it do not full fill my requirement.
    i have checkbox with 4 values user can select all four values or can select any of the value. Based on the selected value i need to fire alert on a textbox and date field. Help is much appreciated.

    Hey Dilip,
    You can write your own javascript logic to achieve the same in content editor webpart on newform of list. try below links and let me know if you need further details.
    using jquery validation plugin to validate
    choice filed
    JQuery validation-select required if checkbox checked
    Thanks.

  • How to Update the Date in PL/SQL using a variable?

    Hi,
    I am setting up a varchar of an update statement and would like to put a date variable for the value. It works when I just put SYSDATE in the statement, yet doesn't when I put the date variable. Gives me an ORA-0904 error. Thanks.
    DECLARE
    v_upd VARCHAR2(32767); -- update statement
    l_date varchar(20);
    BEGIN
    select sysdate into l_date from dual;
    v_upd := 'UPDATE table_name SET LAST_MODIFIED_DATE = ' ||
    l_date ;
    v_upd := v_upd || ' where xyz =''123'' ';
    EXECUTE IMMEDIATE v_upd;
    EXCEPTION
    WHEN OTHERS THEN
    ROLLBACK;
    RAISE;
    END;

    And you don't need to select sysdate from dual.
    SQL> begin
      2     UPDATE table_name
      3     SET    LAST_MODIFIED_DATE = sysdate
      4     where  xyz = '123';
      5
      6     dbms_output.put_line(sql%rowcount || ' rows updated.');
      7  end;
      8  /
    55103 rows updated.
    PL/SQL procedure successfully completed.

  • How to auto update date column without using trigger

    Hi,
    How to write below MYSQL query in Oracle 10g :
    CREATE TABLE example_timestamp (
    Id number(10) NOT NULL PRIMARY KEY,
    Data VARCHAR(100),
         Date_time TIMESTAMP DEFAULT current_timestamp on update current_timestamp
    I need to auto update the Date_Time column without using trigger when ever i update a record.
    Example shown below is from MYSQL. I want to perform the below steps in ORACLE to auto update Date_Time column.
    mysql> INSERT INTO example_timestamp (data)
    VALUES ('The time of creation is:');
    mysql> SELECT * FROM example_timestamp;
    | id | data | Date_Time |
    | 1 | The time of creation is: | 2012-06-28 12:37:22 |
    mysql> UPDATE example_timestamp
    SET data='The current timestamp is: '
    WHERE id=1;
    mysql> SELECT * FROM example_timestamp;
    | id | data | Date_Time |
    | 1 | The current timestamp is: | 2012-06-28 12:38:55 |
    Regards,
    Yogesh.

    Is there no functionality in oracle to auto update date column without using trigger??
    I dont want to update the date column in UPDATE statement.
    The date column should automatically get updated when ever i execute an Update statement.

  • How to read data from the data provider using javascript

    Hi,
    Please let me know how to read the data from the dataprovider using javascript(query assigned to the data provider).
    My query has filter charateristics, free charateristics, charateristics in rows and key figure in column.
    Thanks a lot for your kind help
    Regards
    Kandasamy

    Kandaswamy,
    Assign an ID to your table item , then in JavaScript , you can use ID.innerHTML and you will get the HTML code within that table for the same , then you can find out how best to get the exact value you desire from the innerHTML value which is a string with the entire HTML from within the table item.
    Arun
    Hope it helps....

  • Getting errors while updating links in Indesign document using javascript

    Hi,
    We are updating the links in InDesign document using javascript. After running the script, we are getting the below errors in Adobe InDesign CC debug.
    When closing the document for first time we are getting the below mentioned errors,
    ASSERT 'fRefCount == 0' in c:\development\citius\source\components\database3\revisioneddatabase\SaLRICache.tpp at line 230 failed.
    Erased item list not empty at block delete time
    blockUID = 10486786 not freed
    Internal error: 904 items were leaked!
    After that we are opening the same document for second time, then we are getting the below mentioned errors,
    ASSERT 'ts_DBPubFile->PlacementUIDIsAvailable(uid)' in c:\development\citius\source\components\database3\revisioneddatabase\SaLRIUtils.tpp at line 195 failed.
    DB failed to create UID!
    ASSERT 'this->FindInIDRangeList(fLastCreatedBlockUID) >= 0' in c:\development\citius\source\components\database3\revisioneddatabase\SaLRICache.tpp at line 476 failed.
    ASSERT 'fLastCreatedBlockUID != kInvalidUID && fLastCreatedItemID != 0' in c:\development\citius\source\components\database3\revisioneddatabase\SaLRICache.tpp at line 467 failed.
    ASSERT '(SaLRIUtils<SnapshotID , SnapshotInfo>::ts_DB)->IsValidUID(itemUID)' in ..\..\..\source\components\database3\revisioneddatabase\SnapshotCache.cpp at line 55 failed.
    Please help us to solve this error in InDesign debug.
    Thanks,
    Vimala L

    You're probably better off raising this in the SDK forum.

  • Which type of index is useful for date columns with time stamp

    Hi all,
    I am using date column in the where clause of an SQL Query. The values stored in the date column are includes timestamp. The query is very slow and there is no index on the date column.
    Can any body suggest which index is better on date columns
    Thanks

    I am using date column in the where clause of an SQL Query.Dates a re hard queries to tune. This ...
    WHERE start_date BETWEEN to_date('01-SEP-05') AND to_date('02-SEP-05')...probably requires a very different execution plan to this...
    WHERE start_date BETWEEN to_date('01-JAN-01') AND to_date('02-SEP-05')Just bunging an index on the date column may speed up your specific query but break something else. So be careful.
    Cheers, APC

  • How to update the data  in database in webdynpro

    I have to update the data in databse table using adaptive rfc in WebDynPro

    Hi,
    You can refer to these links:
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/wdjava/faq%2b-%2bmodels%2b-%2badaptive%2brfc
    Update data into SAP Table
    http://help.sap.com/saphelp_nw70/helpdata/en/41/38bc8f813719488ddc9d9b21251ec3/frameset.htm
    http://help.sap.com/saphelp_nw70/helpdata/en/d5/1558bfa6aa80499113983e738b1b21/frameset.htm
    Regards
    Inder

Maybe you are looking for

  • Issues in Conveyance Allowance amount in Exemption U/S 10

    New issues rise Now.... For New (mid month) joinee at the first month Exemption U/S 10 is calculated based on the Conveyance Allowance amount *12 months (or no. of remaining months for financial yr end), but in my client income tax Exemption U/S 10 b

  • Arabic calender blank in GL after upgrade to 12.1.1

    Dear All, Arabic calender blank after upgrade from 12.0.6 to 12.1.1 in GL application screen, how could i troubleshoot. english calender working fine, this arabic calender showing, its blank when we click the date. please advice me pls

  • Stuck with CDDB server connection

    hello from belgium I am stuck , not knowing how I need to connect to CDDB server. So my imported songs stay track1, track2 etc without a title unless I type him in myself via "file - get info"... see error msg below "unable to connect to the CDDB ser

  • Can I link to a specific slide in another Keynote presentation?

    I am trying to link multiple graphics to another slide presentation as a way to offer additional information for these products if the viewer needs more info, however I do not want to add these information pages to the original presentation because i

  • Fault message types: Why do we need them?

    Hi guys, I have a bpm scenario created, tested and working. This bpm starts with a async receive, a Sync Send to a R3 system by an ABAP proxy and a final async send to the original system. I'm contemplating exception handling and other type of errors