script dynamic activity into RITM to add existing server to an alm_license

Nikora
Giga Expert

hello member,

i have to add into a RITM an dynamic scrypting activity to join an existing server to an existing licence alm_licence,

 

here my script and can't find where is my mystake:

(i have condition in my task for run on SQL Server 2019 Enterprise , the task run, but the entry for "alm_entitlement_asset" is not ok)

 

(function executeRule(current, previous /*null when async*/ ) {


 gs.info('INFO>>> Table:<Scripted Activity> - Script: sa_create_licence_installed - Request: ' + RITM.request);



    try {

//01 sysid RITM
var ritmSysId = current.sys_id; 

//////////////////////////////////////////////////////////////////////////////
//02 definition et recuperation des variables

//version
var version = RITM.variables.v_dc_sql_version_database;
//edition
var edition = RITM.variables.v_dc_sql_edition_selectbox;

//Server
var server = RITM.variables.v_dc_cmdb_ci_reference;

//alm licence
var licence_id = '';

//MSSQL_BYOL_PARTNER - MICROSOFT SQL Server 2019 Enterprise eb725f0cc392ca1022f6bcee05013141
//MSSQL_BYOL_PARTNER - MICROSOFT SQL 2019 Standard 63721f0cc392ca1022f6bcee050131b5

if (edition == "Entreprise"){
switch (version) {
        case 'MsSQL 2016':
licence_id = '';           
break;
        case 'MsSQL 2019':
            licence_id = 'eb725f0cc392ca1022f6bcee05013141';
break;
        case 'MsSQL 2022':
licence_id = '';
                                     
}


}

if (edition == "Standard"){
switch (version) {
        case 'MsSQL 2016':
licence_id = '';           
break;
        case 'MsSQL 2019':
            licence_id = '63721f0cc392ca1022f6bcee050131b5';
break;
        case 'MsSQL 2022':
licence_id = '';

}
}




//  - Determination de la classe de CI
var sys_class_name = 'alm_entitlement_asset'; 

// *** Glide Record Creation *** //
var ciID = '';
            var ciGR = new GlideRecord(sys_class_name);
            ciGR.initialize();

ciGR.allocated_to = server;
ciGR.licensed_by = licence_id;
ciGR.insert();
ciID = ciGR.getUniqueValue();





RITM.setWorkflow(false); //Do not run business rules
            RITM.autoSysFields(false); //Do not update system fields
            RITM.setForceUpdate(true); //Force the update
            RITM.update();




} catch (err) {
        gs.debug('DEBUG>>> Table:<Scripted Activity> - Script: sa_create_licence_installed  - Identified error : ', err);
}

})(current, previous);

 

 

i get the admin roles in training, but i don't know how to check the debug log, if someone know how, it will help me ,)

1 ACCEPTED SOLUTION

Nikora
Giga Expert

finally find the solution via alm_license table:

var licence = 'SL_M_MSSQL2019STD_MSSQL_BYOL_PARTNER';
		var LicGR = new GlideRecord('alm_license');
		LicGR.addQuery("serial_number", licence);
		LicGR.query();
		
		if (LicGR.next()){
			
			var licence_id = LicGR.getValue('sys_id');
				
		
			
			//var licence_id = '63721f0cc392ca1022f6bcee050131b5';
			
			//  - Determination de la classe de CI
			var sys_class_name = 'alm_entitlement_asset'; 
				
				// *** Glide Record Creation *** //
				var ciID = '';
            var ciGR = new GlideRecord(sys_class_name);
            ciGR.initialize();
	
	
				
				ciGR.allocated_to = server;
				ciGR.licensed_by = licence_id;
				
				
				ciGR.insert();
				ciID = ciGR.getUniqueValue();
		
			}

 

View solution in original post

1 REPLY 1

Nikora
Giga Expert

finally find the solution via alm_license table:

var licence = 'SL_M_MSSQL2019STD_MSSQL_BYOL_PARTNER';
		var LicGR = new GlideRecord('alm_license');
		LicGR.addQuery("serial_number", licence);
		LicGR.query();
		
		if (LicGR.next()){
			
			var licence_id = LicGR.getValue('sys_id');
				
		
			
			//var licence_id = '63721f0cc392ca1022f6bcee050131b5';
			
			//  - Determination de la classe de CI
			var sys_class_name = 'alm_entitlement_asset'; 
				
				// *** Glide Record Creation *** //
				var ciID = '';
            var ciGR = new GlideRecord(sys_class_name);
            ciGR.initialize();
	
	
				
				ciGR.allocated_to = server;
				ciGR.licensed_by = licence_id;
				
				
				ciGR.insert();
				ciID = ciGR.getUniqueValue();
		
			}