- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
a week ago
I have a client script that triggers an include script to convert base64 to image, however my client script has two IF statements, the first IF (if (crachaEstagiario)) is working as expected, while the second IF (else if (crachaFuncionario)) works partially, but the replace does not work. Could someone help me?
function onChange(control, oldValue, newValue, isLoading) {
 
    if (isLoading || newValue == '') {
 
        return;
 
    }
 
    var nomeArquivo = 'imagem_cracha.jpg';
    var tipoMime = 'image/jpeg';
    var tabelaDestino = 'x_bdb_anexo_imagem';
 
    var ga = new GlideAjax('global.AnexoImagem');
 
    ga.addParam('sysparm_name', 'anexarImagemBase64Client');
    ga.addParam('sysparm_base64', newValue);
    ga.addParam('sysparm_nome', nomeArquivo);
    ga.addParam('sysparm_mime', tipoMime);
    ga.addParam('sysparm_tabela', tabelaDestino);
 
    ga.getXMLAnswer(function(response) {
 
        if (response) {
 
            try {
 
                var result = JSON.parse(response);
 
                if (result && result.anexoSysId) {
 
                    var v_sys_id_imagem_base64 = result.anexoSysId;
 
                    g_form.setValue('v_sys_id_imagem_base64', v_sys_id_imagem_base64);
 
                    var crachaEstagiario = g_form.getValue('selecione_a_cor_do_seu_novo_cracha_estagiario');
 
                    var crachaFuncionario = g_form.getValue('selecione_novo_cracha_funcionario');
 
                    if (crachaEstagiario) {
 
                        var templateHTML = g_form.getDisplayValue(crachaEstagiario);
 
                        templateHTML = templateHTML.replace('cracha', v_sys_id_imagem_base64);
                        alert(templateHTML);
 
                        g_form.setValue(crachaEstagiario, templateHTML);
 
                    } else if (crachaFuncionario) {
                   
                        var templateHTML = g_form.getValue(crachaFuncionario);
 
                        templateHTML = templateHTML.replace('cracha', v_sys_id_imagem_base64);
                        alert(templateHTML);
 
                        g_form.setValue(crachaFuncionario, templateHTML);
 
                    }
 
                    g_form.showFieldMsg('v_imagem_em_base64', 'Imagem anexada com sucesso!', 'info');
 
                } else {
 
                    g_form.showFieldMsg('v_imagem_em_base64', 'Erro ao anexar imagem.', 'error');
 
                    return;
 
                }
 
            } catch (e) {
 
                g_form.showFieldMsg('v_imagem_em_base64', 'Resposta inválida do servidor.', 'error');
 
                return;
 
            }
 
        } else {
 
            g_form.showFieldMsg('v_imagem_em_base64', 'Nenhuma resposta do servidor.', 'error');
 
            return;
 
        }
 
    });
 
}
 
					
				
			
			
				
			
			
				Solved! Go to Solution.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
a week ago
does that variable have value?
try this and share your findings
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
a week ago
did you add alert and debug?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
a week ago
the alert of the first IF brings the information, however the one of the second IF is empty.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
a week ago
does that variable have value?
try this and share your findings
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
a week ago
Hi @Ariomar de Deus ,
Please review below links-
1. https://www.servicenow.com/community/servicenow-ai-platform-forum/replace-string/m-p/1066218
2. https://www.servicenow.com/community/developer-forum/substitute-for-replace/m-p/1408058
Hope that will help you!
If you found my response helpful, please mark it as helpful and accept it as the solution.
Thank you
Nawal Singh
