0

Changing Client's Name in Smart Projects after creation using Macros

Ahmed Abd El Hameed 2 years ago updated by Dennis Rosenbaum 2 years ago 3

Hello , I am trying to change the client name after creating the smart project but it only changes from the outside not from the inside of the project dashboard 

Image 2411

Image 2412

is there anyway I can change it in both places ? I tried to setNameInternal and it didnt work aswell

here is my code

import com.radzisz.xtrf.utils.velocity.VelocityTagUtils
import com.radzisz.xtrf.model.project.Project
import com.radzisz.xtrf.service.CustomerService
import com.radzisz.xtrf.model.partner.customer.Customer




class ChangeClient {
    def list;
    def params;

    VelocityTagUtils utils = new VelocityTagUtils();

    ChangeClient(list, params){
    this.list = list;
    this.params = params;
    }
CustomerService customers = utils.getService("com.radzisz.xtrf.service.CustomerService")
Customer newCustomer = customers.getByName("DTest2")
def nameOfNewCustomer = newCustomer.getName()

    def runMacro() {
        String customerName
        
        list.each{Project project ->
            project.setCustomerInternal(newCustomer)
            project.getCustomer().setNameInternal(nameOfNewCustomer)
        }
    }
}

new ChangeClient(list, params).runMacro();


You are trying to update the customer itself (I don't think that's something you want). And you are trying to update the internal name. Which is not the right one. You are looking for setName() and setFullname()

Also, don't forget to check the box Macro Modifies Model Data, which is neccesary to change the data in the database.

This piece of code will update the customer's name, you can change the newName variable:

import com.radzisz.xtrf.utils.velocity.VelocityTagUtils
import com.radzisz.xtrf.model.project.Project
import com.radzisz.xtrf.service.CustomerService
import com.radzisz.xtrf.model.partner.customer.Customer




class ChangeClient {
    def list;
    def params;
    def newName = "DTest2";

    VelocityTagUtils utils = new VelocityTagUtils();

    ChangeClient(list, params){
    this.list = list;
    this.params = params;
    }
    

    def runMacro() {
        String customerName
        def debug = ""
        
        list.each{Project project ->
            def customer = project.customer
            debug += "Try to change the name, current name is " + customer.name + "\n"
            customer.setName(newName)
            debug += "Name is updated to " + newName + "\n"
            
            debug += "Try to change the fullname/legalname/internalname, current name is " + customer.fullname + "\n"
            customer.setFullname(newName)
            debug += "Fullname/legalname/internal name is updated to " + newName + "\n"
        }
        
        return debug
    }
}

new ChangeClient(list, params).runMacro();

Thank you for replying so quickly, I really appreciate it. I actually want to change the customer itself to another not just the name of it. that's why I am using setCustomerInternal however i can't get it to work as i want it to.. not sure what I am doing wrong there. I want to run the macro on a project and it changes the client completely to a different client i'll be setting in the code. Is my code the right approach to achieve  that ? 

Thank you very much in advance.

I don't think you can. XTRF is very explicit regarding changing the client after quote/project creation: this isn't possible.