Hi
Based on below link i have created SQL Job on one of our SQL 2016.Everything is working fine.
But in out put it is not displaying
Stopped the job since this is not a Primary Replica
Date10/15/2019 12:05:41 PMLogJob History (TEST-Index)
Step ID1
ServerQNV012C88
Job NameTEST-Index
Step NameAG-Check
Duration00:00:00
Sql Severity0
Sql Message ID14254
Operator Emailed
Operator Net sent
Operator Paged
Retries Attempted0
Message
Executed as user: SAFEWAY01\svcMsSqlserv. The step was cancelled (stopped) as the result of a stop job request.
-- Detect if this instance's role is a Primary Replica.
-- If this instance's role is NOT a Primary Replica stop the job so that it does not go on to the next job step
DECLARE @rc int;
EXEC @rc = master.dbo.fn_hadr_group_is_primary N'my-ag';
IF @rc = 0
BEGIN;
DECLARE @name sysname;
SELECT @name = (SELECT name FROM msdb.dbo.sysjobs WHERE job_id = CONVERT(uniqueidentifier, '$(ESCAPE_NONE(JOBID))'));
EXEC msdb.dbo.sp_stop_job @job_name = @name;
PRINT'Stopped the job since this is not a Primary Replica';
END;