I have an issue where I need to update the value of an object property on a page when (or before) the page is updated.
The logic is simple - If the user changes the status to “Closed” then update the closed_dt. The script works fine and the event is triggered. However, When the event fires the “set” for the attached object " SHPQUALITYObject" the script fails.
WHY!!!
Please Help
if (newStatus == "Closed") {
// Set Closed Date as today
SHPQUALITYObject.set("closed_dt", xwiki.getDate())
//Append the Comment
docSource.setComment(SHPDocComment + " Status CLOSED")
}
The Entire Code
{{groovy}}
def docSource = xcontext.method.input.get(1)
def SHPDocObject = docSource.getObject("SHPDocuments.SHPDocumentClass")
if (SHPDocObject) {
//Lets See if its in Status Control
def SHPTDObject = docSource.getObject("SHPTD.SHPTDClass")
def SHPQUALITYObject = docSource.getObject("SHPQUALITY.SHPQUALITYClass")
if (SHPQUALITYObject) {
//Get the status of This Document (the one thats changing)
def newStatus = SHPQUALITYObject.get("status").value
//Get the old Document (the one that already exists if there is one )
if (xwiki.exists(docSource.fullName)) {
def oldDoc = xwiki.getDocument(docSource.fullName)
def oldSHPQUALITYObject = oldDoc.getObject("SHPQUALITY.SHPQUALITYClass")
//dont use .value here as it dosnt work (unknown Reason)
def oldStatus = oldSHPQUALITYObject.get("status")
if (oldStatus != newStatus) {
//Get the old Comment
def SHPDocComment = docSource.getComment()
// Check What Status Changed and Set Appropriate Stuff
if (newStatus == "Closed") {
// Set Closed Date as today
SHPQUALITYObject.set("closed_dt", xwiki.getDate())
//Append the Comment
docSource.setComment(SHPDocComment + " Status CLOSED")
}
if (oldStatus == "Closed") {
// Remove Closed Date
SHPQUALITYObject.set("closed_dt",null)
//Append the Comment
docSource.setComment(SHPDocComment + " Status REOPENED")
}
}
}
}
}
{{/groovy}}