Page tree
Skip to end of metadata
Go to start of metadata


场景:

一般在流程中审批,会根据业务线去找相应的字段是否能填写值,比如在审批阶段只有业务经理能够编辑技术投入成本,其他人不能编辑


代码:

@WithPlugin('com.hktx.gears.parallel-approval')
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.fc.parallelapproval.service.ComponentLeadService
import com.fc.parallelapproval.beans.ComponentLeadBean


import com.atlassian.jira.security.roles.ProjectRoleManager


// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// 技术投入成本
def trcbField = getFieldByName("技术投入成本")



def issue 
def status
def user1 
def ywzx
if(underlyingIssue){ // If the issue key exists (NOT a CREATE screen)
    // Get the issue key
    issue = ComponentAccessor.issueManager.getIssueObject(underlyingIssue.id)
    // Get the issue's status
    status = issue.status.name
    log.info("select:"+status);

    // 业务主线获取业务线经理
    def ywzxField = ComponentAccessor.customFieldManager.customFieldObjects.findByName("业务主线") 
    
     ywzx = issue.getCustomFieldValue(ywzxField);
    log.info("select:"+ywzx);
    
    def componentLeadService = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentLeadService)
    
    user1 = componentLeadService.queryProjectLeadByProjectName(String.valueOf(ywzx)) 

}

// Set the "技术投入成本" field read-only for ALL screens
trcbField.setReadOnly(true);
log.info("select:2"+currentUser);

if(status == "业务线经理审核"){ // AND the issue status is "业务线经理审核"
    //当是业务经理时
    if(currentUser ==user1){
        trcbField.setReadOnly(false)
    }
        
    log.info("select3:"+user1);
 }




  • No labels