SharePoint: Extended DVWP-Part 2: Using jQuery to write PreSaveAction () practices

Source: Internet
Author: User
Document directory
  • Create an audit record using SharePoint Web Service
  • Now together
  • Other Purposes
  • Want to know more application scenarios?

Through the previous study, we have learned how to use PreSaveAction () in DVWP, and used jQuery to help us create some variables. Next, let's write the variable values to the audit list.

Create an audit record using SharePoint Web Service

The UpdataListItems in the Marc Library provides us with a way to quickly record changes in audit tracking information.

First, record the old field value (or the value of the form itself...

$ (). SPServices ({operation: "UpdateListItems", // The following Cmd determines the insert operation async: false, listName: "FTE Change Audit ", // The display name of the previously created audit list updates: "<Batch OnError = 'contine' PreCalc = 'true'>" + "<Method ID = '1' Cmd = 'new'>" + "<Field Name = 'fromto'> From </Field> "+ // Field Name is 'static name' in the list bar" <Field Name = 'title'> "+ txtOldName +" </Field>" + "<Field Name = 'location'>" + txtOldLoc + "</Field>" + "<Field Name = 'group'>" + txtOldGrp + "</Field>" + "<Field Name = 'position'>" + txtOldPos + "</Field>" + "<Field Name = 'workshift '>" + txtOldShift + "</Field>" + "<Field Name = 'fte'>" + txtOldFTE + "</Field>" + "<Field Name = 'effdate'>" + txtEffDate + "</Field>" + "<Field Name = 'changetype '>" + txtChangeType + "</Field>" + "</Method>" + "</Batch> ", completefunc: function (xData, Status ){}});

... Then, repeat the above process for all new (or modified) records. Change the FromTo value To; note that we use the same EffDate in these two processes (your requirements may be different ). ChangeType can be automatically set or calculated based on some existing changes.

Now together

Although the code you write may be modified based on your needs, so far, our PreSaveAction () is shown as follows:

  function PreSaveAction() {     var txtChangeType = "Update";     var txtNewName = $("input[name*=$ff1_]").val();     var txtOldName = $("span[id*=_ff9_]").text();     var txtNewPos = $("input[name*=$ff3_]").val();     var txtOldPos = $("span[id*=_ff11_]").text();     var txtNewShift = $("select[name*=$ff4_]").val();     var txtOldShift = $("span[id*=_ff12_]").text();     var txtNewFTE = $("input[name*=$ff5_]").val();     var txtOldFTE = $("span[id*=_ff13_]").text();     var txtNewGrp = $("input[name*=$ff2_]").val();     var txtOldGrp = $("span[id*=_ff10_]").text();     var txtNewLoc = $("input[name*=$ff6_]").val();     var txtOldLoc = $("span[id*=_ff14_]").text();     var txtEffDate = $("input[name*=$ff7_]").val();     $().SPServices({          operation: "UpdateListItems",          async: false,          listName: "FTE Change Audit",          updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +                    "<Method ID='1' Cmd='New'>" +                         "<Field Name='FromTo'>From</Field>" +                         "<Field Name='Title'>" + txtOldName + "</Field>" +                         "<Field Name='Location'>" + txtOldLoc + "</Field>" +                         "<Field Name='Group'>" + txtOldGrp + "</Field>" +                         "<Field Name='Position'>" + txtOldPos + "</Field>" +                         "<Field Name='WorkShift'>" + txtOldShift + "</Field>" +                         "<Field Name='FTE'>" + txtOldFTE + "</Field>" +                         "<Field Name='EffDate'>" + txtEffDate + "</Field>" +                         "<Field Name='ChangeType'>" + txtChangeType + "</Field>" +                    "</Method>" +               "</Batch>",          completefunc: function(xData, Status) {          }     });     $().SPServices({          operation: "UpdateListItems",          async: false,          listName: "FTE Change Audit",          updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +                    "<Method ID='1' Cmd='New'>" +                         "<Field Name='FromTo'>To</Field>" +                         "<Field Name='Title'>" + txtNewName + "</Field>" +                         "<Field Name='Location'>" + txtNewLoc + "</Field>" +                         "<Field Name='Group'>" + txtNewGrp + "</Field>" +                         "<Field Name='Position'>" + txtNewPos + "</Field>" +                         "<Field Name='WorkShift'>" + txtNewShift + "</Field>" +                         "<Field Name='FTE'>" + txtNewFTE + "</Field>" +                         "<Field Name='EffDate'>" + txtEffDate + "</Field>" +                         "<Field Name='ChangeType'>" + txtChangeType + "</Field>" +                    "</Method>" +               "</Batch>",          completefunc: function(xData, Status) {          }     });     return true;};
Other Purposes

What can you do through PreSaveAction?

1. Column verification-make sure that the data you are about to write to the database meets some requirements, such:

I. The end date is after the start date

Ii. A time period should contain at least x days (or the number of days is greater than x days)

Iii. A person already exists in a list (or does not exist in a list)

Iv. If some optional fields are required after some fields are entered

V.

2. Add "what do you mean ...?" Function

I. "... do you want to modify it, but do not update the validity period ?"

Ii. "... will this date be set later ?"

Iii. "... is this name very close to this person ?"

Iv. "... refers to the converted result? Or the final result ?"

V.

3. Audit Trail required

4. Confirm whether to delete

5. Search for information stored in this list item

5. other ideas...

Want to know more application scenarios?

Search for PreSaveAction () to see what other blog authors have.

 

Next time: How to use a custom drop-down list box in DVWP? There are some best practices on the internet, whether you are using DVWP or not. However, if you need to use the cascade drop-down box in your DVWP, you need to plan in advance. We will start this plan and point out some possible traps.

In the next four articles, we will implement the cascade drop-down list box function in DVWP. The owner of the corresponding list manages its content and relationships in the SharePoint list.

 

References

SharePoint: Extending the DVWP-Part 14: Putting PreSaveAction () to Work with jQuery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.