Buenas tardes, estoy intentando modificar el valor del campo descripción o de un campo pesonalizado con scriptrunner behaviour cloud jira cloud pero no lo hace, es posible?
aqui el código:
Hi @stephen
Welcome to Atlassian Community!
You can do it easily using Jira Automation as mentioned below.
Go to Settings --> System --> Global Automation --> Create Rule
Regards,
Ashish
Hi @Ashish Bijlwan thank you very much for your response, I had done it as you indicated, the problem is that the text: Hello World is seen after the issue is created and I need that Hello World text to be displayed when opening the form to create the issue, in the Load event it seems to me, please do you know if it is possible to do that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @stephen
This can be done using ScriptRunner Behaviour. Here is the code for that.
const descriptionValue = getFieldById("description").getValue();
if (typeof descriptionValue !== "string") {
const descriptionValueContent = descriptionValue.content.toString();
if (!descriptionValueContent) {
getFieldById("description").setValue({
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Hello World ",
"marks": [
{
"type": "strong"
}
]
})
}
}
Regards,
Ashish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ashish Bijlwan thank you very much for the help but your script does not work, I have also tried the following:
var campoInstrucciones = getFieldById("customfield_10061");
if (campoInstrucciones) {
campoInstrucciones.setValue("HELLO WORLD");
console.log("El texto 'HELLO WORLD' se ha establecido correctamente en el campo Instrucciones.");
} else {
console.error("No se encontró el campo Instrucciones con el ID 'helptext'.");
}
with a custom field but it doesn't make the change either, it seems to me that scriptrunner behaviour cloud in jira cloud doesn't allow modifying the values of the fields in a form
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @stephen
Did you tried this code for field Description (system field which is set to use the WIKI field renderer) , because it's working for me:
Also, for other Text type custom field which is set to use the DEFAULT Text field renderer, kindly use below
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Ashish Bijlwan I don't doubt that your script works correctly, but it seems that I have something wrong configured or maybe it's the type of project. I don't know, I'll send you the images, I follow the steps as you indicate but it doesn't work. What type of project do you have configured where the script works? I'm using Jira Cloud - Jira Service Management - Support Project and the issue is a task.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @stephen
Currently ScriptRunner Behaviours only supports Jira Software (Company Managed Projects). Refer https://docs.adaptavist.com/sr4jc/latest/features/behaviours/behaviours-supported-fields-and-products for more info.
I am using Jira Software (Company Managed Projects).
Regards,
Ashish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ashish Bijlwan , thank you very much for your support, now the Hello World works in the description field, please ask one more question, I need to show a list of Jenkins jobs in that description field and I have the following script but it doesn't work, is it possible to show that list in the description field in the same context of scriptrunner behavior? script:
const jenkinsUrl = 'jenkinsurl/api/json?tree=jobs%5Bname%2Curl%2Cjobs%5Bname%2Curl%5D%5D';
const base64Credentials = 'usuario:apitoken';
const authHeader = 'Basic ' + base64Credentials;
let errorMessage = '';
function setDescription(content) {
const descriptionField = getFieldById('description');
if (descriptionField) {
descriptionField.setValue({
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": content
}
]
}
]
});
}
}
function processJobs(jobs) {
let jobList = '';
jobs.forEach(job => {
jobList += `${job.name} - ${job.url}\n`;
if (job.jobs && Array.isArray(job.jobs)) {
job.jobs.forEach(subJob => {
jobList += ` ${subJob.name} - ${subJob.url}\n`;
});
}
});
return jobList;
}
setDescription('hola mundo');
fetch(jenkinsUrl, {
method: 'GET',
headers: {
'Authorization': authHeader,
'Accept': 'application/json'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
let jobList = ''; // Inicializamos la lista de jobs
// Verificar si se obtuvieron jobs
if (data.jobs && Array.isArray(data.jobs)) {
jobList = processJobs(data.jobs);
// Si hay jobs, procedemos a llenar el campo de descripción
if (jobList) {
setDescription(jobList);
} else {
errorMessage = 'No se encontraron jobs para mostrar.';
}
} else {
errorMessage = 'No se encontraron jobs en la respuesta de Jenkins.';
}
})
.catch(error => {
// En caso de error en la solicitud o procesamiento
errorMessage = `Error al obtener los jobs de Jenkins: ${error.message}`;
})
.finally(() => {
// Si hubo un error, asignamos el mensaje de error al campo descripción
if (errorMessage) {
setDescription(errorMessage); // Establecer el contenido de error como valor del campo
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @stephen
For this please raise help request on https://the-adaptavist-group-support.atlassian.net/servicedesk/customer/user/login they can help you with the correct function to call the Jenkins jobs with in Description field.
Regards,
Ashish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.