3

i am trying to update a specific document by using rest service control. I have set up the control (documentJsonService, pathInfo, form name etc) I know that i have to perform a post (patch) request to the url of the service followed by /unid/ (same way as i ve done to read the document using the same rest).

I have an input field and a button. I want to enter a value to the field, press the button and update a field in the document with the value. How can i do this request?

mike_x_
  • 1,900
  • 3
  • 35
  • 69

1 Answers1

0

This is the js function i used in worklight to update a document in Domino:

function updateDoc(docId,newValue) {
    var identity = Base64.encode("myDominoUsername:myDominoPassword");  
    path = "/Databases/Temp/dominoApp.nsf/BestRestTest.xsp/updateService/unid/"+docId;
    var input = {
    method : 'post',
    returnedContentType : 'json',
    headers:{
        Authorization: "Basic "+"b4lzdD234GG3M6SdW1XI=" //base64 encoding of your //credentials, see above. The function Base64.encode can be found by googling about it in //js. So you replace this string with identity variable.
        "X-HTTP-Method-Override":"PATCH",
        "Content-Type":"application/json"
    },
    body: { 
         contentType: 'application/json; charset=utf-8', 
         content: JSON.stringify({"theField":newValue}) 
         },
    path : path
    };
    return WL.Server.invokeHttp(input);
}

Now on the Domino side i have added an extension library REST control (alternatively you can do it with Domino Data Service). The properties i ve added are:

  • pathInfo: whatever you want
  • service: documentJsonService
  • computeWithForm:true
  • defaultItems:true
  • formName:myformName

This is just client side javascript, so you can do it in a similar way from an XPage.

mike_x_
  • 1,900
  • 3
  • 35
  • 69