Hi All,

I am new marklogic I writed a spwan function to update the documents and I use 
xdmp:node-replace and xdmp:node-insert-child inside the spwan function but 
there is no update is happen inside the cod.
My code is below

let $start := 225001
let $end := 226000
return xdmp:spawn-function(function() {
let $log := xdmp:log(concat("Running update for chunk", $start, " to ",$end))
for $uri in 
cts:uris((),(),cts:and-query((cts:element-query(xs:QName("dp:document-properties"),
 "*"))))[$start to $end]
let $itemPii := (tokenize($uri, "/")[last()-1])
let $uri := 
replace("https://acc.vtw.elsevier.com/property/pii/itempii?category=cs:consyn";, 
"itempii", $itemPii)
        let $psResponse :=
            json:transform-from-json(xdmp:quote(
                xdmp:http-get($uri,
                    <options xmlns="xdmp:http">
                       <authentication method="digest">
                         <username>{xs:string("")}</username>
                         <password>{xs:string("")}</password>
                       </authentication>
                       <verify-cert>false</verify-cert>
                     </options>)[2]))
let $copyright_info := 
eninglib:construct-copyright-notice-element($itemPii,$psResponse)
let $license_info := 
eninglib:construct-copyright-licenseLine-element($itemPii,$psResponse)
return
(
if(exists($copyright_info) or exists($license_info))
then
(
let $log := xdmp:log(concat("Copyright update-", $itemPii, "Copyright Info - 
",$copyright_info,"License Info -",$license_info))
let $node :=  doc($uri)//dp:document-properties/dp:copyrightInformation

let $cp := if (exists($node))
then 
(xdmp:node-replace($node,<dp:copyrightInformation>{$copyright_info,$license_info}</dp:copyrightInformation>))
else 
(xdmp:node-insert-child(doc($uri)//dp:document-properties,<dp:copyrightInformation>{$copyright_info,$license_info}</dp:copyrightInformation>))


let $oanode := doc($uri)//cps:consyn-properties/cps:oa-last-updated-timestamp
let $oa := if(exists($oanode))
then(xdmp:node-replace($oanode,<cps:oa-last-updated-timestamp>{current-dateTime()}</cps:oa-last-updated-timestamp>))
else(xdmp:node-insert-child(doc($uri)//cps:consyn-properties,<cps:oa-last-updated-timestamp>{current-dateTime()}</cps:oa-last-updated-timestamp>))
return ()
)
else()
)
},<options xmlns="xdmp:eval">

            <transaction-mode>update-auto-commit
</transaction-mode>
        </options>)

Kindly do needful.

Thanks & Regards,
Siva

_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to