I want to get the value of a read-only column using a script.
Answer¶
Get it with ".text()".
Overview¶
In Pleasanter, read-only columns are composed of span tags (usually input tags). Due to the specifications of the jQuery library that can be used in "Script", values can be obtained by using ".val()" for columns composed of input tags and ".text()" for items composed of span tags. Therefore, even if you use the sample script code in the official Pleasanter manual or FAQ, which assumes normal input tags, you may not be able to obtain values for read-only columns, so please read accordingly.
When A Column With A Unit Set Is Made Read-only¶
When a numeric value column with a unit set is made read-only, the unit will be included in the display, and ".text()" will retrieve the value with the unit. If the unit is not required, add a process to delete the unit as appropriate.
Code Samples¶
- This is a sample that outputs the read-only values of Title, Category A, and DateA in a message when the editing screen is opened.
JavaScript¶
$p.events.on_editor_load = function () {
$p.setMessage(
'#Message',
JSON.stringify({
Css: 'alert-success',
Text: `The title of this record is "${$p.getControl('Title').text()}", its classA is "${$p.getControl('ClassA').text()}", and its dateA is "${$p.getControl('DateA').text()}". `
})
);
}
- This is a sample that outputs only the value of read-only NumA (with unit setting) in a message when the editing screen is opened.
JavaScript¶
$p.events.on_editor_load = function () {
$p.setMessage(
'#Message',
JSON.stringify({
Css: 'alert-success',
Text: `The NumA of this record is "${$p.getControl('NumA').text().replace('day','')}". `
})
);
}
When Using A Server Script¶
When using a Server Script, you can get numeric value column in the "model" object regardless of whether the item is input-enabled or read-only. Even if the numeric value column is read-only and has a unit, only the value is retrieved in the "model" object.